Skip to content

Commit

Permalink
Remove phpstan/phpstan-webmozart-assert dependency (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
8ctopus authored Oct 9, 2024
1 parent ab30d1d commit ac0925a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"require-dev": {
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^7.0|^8.0|^9.0",
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpstan/extension-installer": "^1.0"
},
"autoload": {
Expand Down
23 changes: 18 additions & 5 deletions src/Cron/CronExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use InvalidArgumentException;
use LogicException;
use RuntimeException;
use Webmozart\Assert\Assert;

/**
* CRON expression parser that can determine whether or not a CRON expression is
Expand Down Expand Up @@ -200,7 +199,12 @@ public function __construct(string $expression, ?FieldFactoryInterface $fieldFac
public function setExpression(string $value): CronExpression
{
$split = preg_split('/\s/', $value, -1, PREG_SPLIT_NO_EMPTY);
Assert::isArray($split);

if (!\is_array($split)) {
throw new InvalidArgumentException(
$value . ' is not a valid CRON expression'
);
}

$notEnoughParts = \count($split) < 5;

Expand Down Expand Up @@ -334,7 +338,10 @@ public function getMultipleRunDates(int $total, $currentTime = 'now', bool $inve
$currentTime = new DateTime($currentTime);
}

Assert::isInstanceOf($currentTime, DateTime::class);
if (!$currentTime instanceof DateTime) {
throw new InvalidArgumentException('invalid current time');
}

$currentTime->setTimezone(new DateTimeZone($timeZone));

$matches = [];
Expand Down Expand Up @@ -420,7 +427,10 @@ public function isDue($currentTime = 'now', $timeZone = null): bool
$currentTime = new DateTime($currentTime);
}

Assert::isInstanceOf($currentTime, DateTime::class);
if (!$currentTime instanceof DateTime) {
throw new InvalidArgumentException('invalid current time');
}

$currentTime->setTimezone(new DateTimeZone($timeZone));

// drop the seconds to 0
Expand Down Expand Up @@ -462,7 +472,10 @@ protected function getRunDate($currentTime = null, int $nth = 0, bool $invert =
$currentDate = new DateTime('now');
}

Assert::isInstanceOf($currentDate, DateTime::class);
if (!$currentDate instanceof DateTime) {
throw new InvalidArgumentException('invalid current date');
}

$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());
Expand Down

0 comments on commit ac0925a

Please sign in to comment.