diff --git a/composer.json b/composer.json index d77096c..fdb46ee 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Cron/CronExpression.php b/src/Cron/CronExpression.php index 7f0dab0..f3d8eb0 100644 --- a/src/Cron/CronExpression.php +++ b/src/Cron/CronExpression.php @@ -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 @@ -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; @@ -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 = []; @@ -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 @@ -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());