upgrade to laravel 8.x

This commit is contained in:
2021-05-30 08:20:41 +00:00
parent 41b78a0599
commit 3ad6ed8bfa
2333 changed files with 113904 additions and 59058 deletions

View File

@@ -1,54 +1,52 @@
<?php
declare(strict_types=1);
namespace Cron;
use InvalidArgumentException;
/**
* CRON field factory implementing a flyweight factory
* @link http://en.wikipedia.org/wiki/Cron
* CRON field factory implementing a flyweight factory.
*
* @see http://en.wikipedia.org/wiki/Cron
*/
class FieldFactory
class FieldFactory implements FieldFactoryInterface
{
/**
* @var array Cache of instantiated fields
*/
private $fields = array();
private $fields = [];
/**
* Get an instance of a field object for a cron expression position
* Get an instance of a field object for a cron expression position.
*
* @param int $position CRON expression position value to retrieve
*
* @return FieldInterface
* @throws InvalidArgumentException if a position is not valid
*/
public function getField($position)
public function getField(int $position): FieldInterface
{
if (!isset($this->fields[$position])) {
switch ($position) {
case 0:
$this->fields[$position] = new MinutesField();
break;
case 1:
$this->fields[$position] = new HoursField();
break;
case 2:
$this->fields[$position] = new DayOfMonthField();
break;
case 3:
$this->fields[$position] = new MonthField();
break;
case 4:
$this->fields[$position] = new DayOfWeekField();
break;
default:
throw new InvalidArgumentException(
($position + 1) . ' is not a valid position'
);
}
return $this->fields[$position] ?? $this->fields[$position] = $this->instantiateField($position);
}
private function instantiateField(int $position): FieldInterface
{
switch ($position) {
case CronExpression::MINUTE:
return new MinutesField();
case CronExpression::HOUR:
return new HoursField();
case CronExpression::DAY:
return new DayOfMonthField();
case CronExpression::MONTH:
return new MonthField();
case CronExpression::WEEKDAY:
return new DayOfWeekField();
}
return $this->fields[$position];
throw new InvalidArgumentException(
($position + 1) . ' is not a valid position'
);
}
}