diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 814ab29..6b22e2e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.3', '7.4', '8.0', '8.1'] + php: ['7.4', '8.0', '8.1'] stability: [ prefer-lowest, prefer-stable ] name: PHP ${{ matrix.php }} - ${{ matrix.stability }} tests diff --git a/composer.json b/composer.json index 5e1e670..1853c3d 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php" : "^7.3 || ^8.0" + "php" : "^7.4 || ^8.0" }, "require-dev": { "phpunit/phpunit" : "^8.5.21 || ^9.5" diff --git a/src/CronExpression.php b/src/CronExpression.php index 61c79f6..f129e11 100644 --- a/src/CronExpression.php +++ b/src/CronExpression.php @@ -4,32 +4,15 @@ class CronExpression { - /** @var string */ - public $raw; - - /** @var MinutesField */ - public $minute; - - /** @var HoursField */ - public $hour; - - /** @var DaysOfMonthField */ - public $day; - - /** @var MonthsField */ - public $month; - - /** @var DaysOfWeekField */ - public $weekday; - - /** @var string */ - public $locale; - - /** @var bool */ - public $timeFormat24hours; - - /** @var array */ - public $translations; + public string $raw; + public MinutesField $minute; + public HoursField $hour; + public DaysOfMonthField $day; + public MonthsField $month; + public DaysOfWeekField $weekday; + public string $locale; + public bool $timeFormat24hours; + public array $translations; public function __construct(string $cron, string $locale = 'en', bool $timeFormat24hours = false) { @@ -61,9 +44,7 @@ public function langCountable(string $type, int $number) { $array = $this->translations[$type]; - $value = isset($array[$number]) - ? $array[$number] - : ($array['default'] ?: ''); + $value = $array[$number] ?? ($array['default'] ?: ''); return str_replace(':number', $number, $value); } @@ -86,6 +67,9 @@ protected function ensureLocaleExists(string $fallbackLocale = 'en') } } + /** + * @throws TranslationFileMissingException + */ protected function loadTranslations() { $this->translations = [ diff --git a/src/CronTranslator.php b/src/CronTranslator.php index 01bbb22..c1ff48b 100644 --- a/src/CronTranslator.php +++ b/src/CronTranslator.php @@ -6,7 +6,7 @@ class CronTranslator { - private static $extendedMap = [ + private static array $extendedMap = [ '@yearly' => '0 0 1 1 *', '@annually' => '0 0 1 1 *', '@monthly' => '0 0 1 * *', @@ -67,7 +67,7 @@ protected static function orderFields(array $fields) ); } - protected static function filterType(array $fields, ...$types) + protected static function filterType(array $fields, ...$types): array { return array_filter($fields, function (Field $field) use ($types) { return $field->hasType(...$types); diff --git a/src/CronType.php b/src/CronType.php index 5250de5..3c4629b 100644 --- a/src/CronType.php +++ b/src/CronType.php @@ -8,17 +8,10 @@ class CronType 'Every', 'Increment', 'Multiple', 'Once', ]; - /** @var string */ - public $type; - - /** @var ?int */ - public $value; - - /** @var ?int */ - public $count; - - /** @var ?int */ - public $increment; + public string $type; + public ?int $value; + public ?int $count; + public ?int $increment; private function __construct(string $type, ?int $value = null, ?int $count = null, ?int $increment = null) { @@ -48,6 +41,9 @@ public static function once(int $value): CronType return new static('Once', $value); } + /** + * @throws CronParsingException + */ public static function parse(string $expression): CronType { // Parse "*". diff --git a/src/DaysOfMonthField.php b/src/DaysOfMonthField.php index 5461cef..16143f2 100644 --- a/src/DaysOfMonthField.php +++ b/src/DaysOfMonthField.php @@ -4,7 +4,7 @@ class DaysOfMonthField extends Field { - public $position = 2; + public int $position = 2; public function translateEvery() { @@ -38,16 +38,16 @@ public function translateMultiple() ]); } - public function translateOnce() + public function translateOnce(): ?string { $month = $this->expression->month; if ($month->hasType('Once')) { - return; // MonthsField adapts to "On January the 1st". + return null; // MonthsField adapts to "On January the 1st". } if ($month->hasType('Every') && ! $month->dropped) { - return; // MonthsField adapts to "The 1st of every month". + return null; // MonthsField adapts to "The 1st of every month". } if ($month->hasType('Every') && $month->dropped) { diff --git a/src/DaysOfWeekField.php b/src/DaysOfWeekField.php index 7ed1ecf..60a615a 100644 --- a/src/DaysOfWeekField.php +++ b/src/DaysOfWeekField.php @@ -4,7 +4,7 @@ class DaysOfWeekField extends Field { - public $position = 4; + public int $position = 4; public function translateEvery() { @@ -43,7 +43,7 @@ public function translateOnce() ]); } - public function format() + public function format(): string { $weekday = $this->getValue() === 0 ? 7 : $this->getValue(); diff --git a/src/Field.php b/src/Field.php index 0fdfb68..83470b4 100644 --- a/src/Field.php +++ b/src/Field.php @@ -4,20 +4,11 @@ abstract class Field { - /** @var CronExpression */ - public $expression; - - /** @var string */ - public $rawField; - - /** @var CronType */ - public $type; - - /** @var bool */ - public $dropped = false; - - /** @var int */ - public $position; + public CronExpression $expression; + public string $rawField; + public CronType $type; + public bool $dropped = false; + public int $position; public function __construct(CronExpression $expression, string $rawField) { diff --git a/src/HoursField.php b/src/HoursField.php index 3757837..7bb91c3 100644 --- a/src/HoursField.php +++ b/src/HoursField.php @@ -4,7 +4,7 @@ class HoursField extends Field { - public $position = 1; + public int $position = 1; public function translateEvery() { diff --git a/src/MinutesField.php b/src/MinutesField.php index 0e58747..926efb1 100644 --- a/src/MinutesField.php +++ b/src/MinutesField.php @@ -4,7 +4,7 @@ class MinutesField extends Field { - public $position = 0; + public int $position = 0; public function translateEvery() { diff --git a/src/MonthsField.php b/src/MonthsField.php index ab2343a..71b54a2 100644 --- a/src/MonthsField.php +++ b/src/MonthsField.php @@ -4,7 +4,7 @@ class MonthsField extends Field { - public $position = 3; + public int $position = 3; public function translateEvery() { @@ -52,6 +52,9 @@ public function translateOnce() ]); } + /** + * @throws CronParsingException + */ public function format() { if ($this->getValue() < 1 || $this->getValue() > 12) {