Skip to content

Commit

Permalink
Fixed PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmantank committed Jan 14, 2022
1 parent 99a8406 commit d81a567
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
],
"require": {
"php": "^7.2|^8.0",
"webmozart/assert": "^1.7.0"
"webmozart/assert": "^1.0"
},
"require-dev": {
"phpstan/phpstan": "^0.12",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^7.0|^8.0|^9.0",
"phpstan/phpstan-webmozart-assert": "^0.12.7",
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpstan/extension-installer": "^1.0"
},
"autoload": {
Expand All @@ -35,7 +35,7 @@
"mtdowling/cron-expression": "^1.0"
},
"scripts": {
"phpstan": "./vendor/bin/phpstan analyse -l max src tests",
"phpstan": "./vendor/bin/phpstan analyze",
"test": "phpunit"
}
}
13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
parameters:
checkMissingIterableValueType: false

ignoreErrors:
- '#Call to an undefined method DateTimeInterface::add\(\)#'
- '#Call to an undefined method DateTimeInterface::modify\(\)#'
- '#Call to an undefined method DateTimeInterface::setDate\(\)#'
- '#Call to an undefined method DateTimeInterface::setTime\(\)#'
- '#Call to an undefined method DateTimeInterface::setTimezone\(\)#'
- '#Call to an undefined method DateTimeInterface::sub\(\)#'

level: max

paths:
- src/
3 changes: 2 additions & 1 deletion src/Cron/AbstractField.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ public function isInIncrementsOfRanges(int $dateValue, string $value): bool

// Generate the requested small range
$rangeChunks = explode('-', $range, 2);
$rangeStart = $rangeChunks[0];
$rangeStart = (int) $rangeChunks[0];
$rangeEnd = $rangeChunks[1] ?? $rangeStart;
$rangeEnd = (int) $rangeEnd;

if ($rangeStart < $this->rangeStart || $rangeStart > $this->rangeEnd || $rangeStart > $rangeEnd) {
throw new \OutOfRangeException('Invalid range start requested');
Expand Down
3 changes: 3 additions & 0 deletions src/Cron/CronExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ protected function getRunDate($currentTime = null, int $nth = 0, bool $invert =
$currentDate->setTimezone(new DateTimeZone($timeZone));
// Workaround for setTime causing an offset change: https://bugs.php.net/bug.php?id=81074
$currentDate = DateTime::createFromFormat("!Y-m-d H:iO", $currentDate->format("Y-m-d H:iP"), $currentDate->getTimezone());
if ($currentDate === false) {
throw new \RuntimeException('Unable to create date from format');
}
$currentDate->setTimezone(new DateTimeZone($timeZone));

$nextRun = clone $currentDate;
Expand Down
11 changes: 7 additions & 4 deletions src/Cron/DayOfMonthField.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,18 @@ public function isSatisfiedBy(DateTimeInterface $date, $value, bool $invert): bo
// Check to see if this is the nearest weekday to a particular value
if (strpos($value, 'W')) {
// Parse the target day
/** @phpstan-ignore-next-line */
$targetDay = (int) substr($value, 0, strpos($value, 'W'));
// Find out if the current day is the nearest day of the week
/** @phpstan-ignore-next-line */
return $date->format('j') === self::getNearestWeekday(
$nearest = self::getNearestWeekday(
(int) $date->format('Y'),
(int) $date->format('m'),
$targetDay
)->format('j');
);
if ($nearest) {
return $date->format('j') === $nearest->format('j');
}

throw new \RuntimeException('Unable to return nearest weekday');
}

return $this->isSatisfied((int) $date->format('d'), $value);
Expand Down
1 change: 0 additions & 1 deletion src/Cron/DayOfWeekField.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function isSatisfiedBy(DateTimeInterface $date, $value, bool $invert): bo

// Find out if this is the last specific weekday of the month
if (strpos($value, 'L')) {
/** @phpstan-ignore-next-line */
$weekday = $this->convertLiterals(substr($value, 0, strpos($value, 'L')));
$weekday %= 7;

Expand Down
2 changes: 1 addition & 1 deletion src/Cron/HoursField.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function isSatisfiedBy(DateTimeInterface $date, $value, bool $invert): bo

// Are we on the edge of a transition
$lastTransition = $this->getPastTransition($date);
if (($lastTransition !== null) && ($lastTransition["ts"] > ($date->format('U') - 3600))) {
if (($lastTransition !== null) && ($lastTransition["ts"] > ((int) $date->format('U') - 3600))) {
$dtLastOffset = clone $date;
$this->timezoneSafeModify($dtLastOffset, "-1 hour");
$lastOffset = $dtLastOffset->getOffset();
Expand Down

0 comments on commit d81a567

Please sign in to comment.