Skip to content

Commit

Permalink
feat: bump php level to 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris53897 committed Sep 30, 2021
1 parent 73ca00c commit 76c066d
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"require": {
"php" : "^7.3 || ^8.0"
"php" : "^7.4 || ^8.0"
},
"require-dev": {
"phpunit/phpunit" : "^8.5.21 || ^9.5"
Expand Down
42 changes: 13 additions & 29 deletions src/CronExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand All @@ -86,6 +67,9 @@ protected function ensureLocaleExists(string $fallbackLocale = 'en')
}
}

/**
* @throws TranslationFileMissingException
*/
protected function loadTranslations()
{
$this->translations = [
Expand Down
4 changes: 2 additions & 2 deletions src/CronTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 * *',
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 7 additions & 11 deletions src/CronType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 "*".
Expand Down
8 changes: 4 additions & 4 deletions src/DaysOfMonthField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class DaysOfMonthField extends Field
{
public $position = 2;
public int $position = 2;

public function translateEvery()
{
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/DaysOfWeekField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class DaysOfWeekField extends Field
{
public $position = 4;
public int $position = 4;

public function translateEvery()
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public function translateOnce()
]);
}

public function format()
public function format(): string
{
$weekday = $this->getValue() === 0 ? 7 : $this->getValue();

Expand Down
19 changes: 5 additions & 14 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/HoursField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class HoursField extends Field
{
public $position = 1;
public int $position = 1;

public function translateEvery()
{
Expand Down
2 changes: 1 addition & 1 deletion src/MinutesField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class MinutesField extends Field
{
public $position = 0;
public int $position = 0;

public function translateEvery()
{
Expand Down
5 changes: 4 additions & 1 deletion src/MonthsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class MonthsField extends Field
{
public $position = 3;
public int $position = 3;

public function translateEvery()
{
Expand Down Expand Up @@ -52,6 +52,9 @@ public function translateOnce()
]);
}

/**
* @throws CronParsingException
*/
public function format()
{
if ($this->getValue() < 1 || $this->getValue() > 12) {
Expand Down

0 comments on commit 76c066d

Please sign in to comment.