Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove phpstan/phpstan-webmozart-assert dependency #187

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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