Skip to content

Commit 7be1c03

Browse files
committed
bug #51821 Add test for 0 and '0' in PeriodicalTrigger and fix '0' case error (ardentsword)
This PR was merged into the 6.4 branch. Discussion ---------- Add test for 0 and '0' in PeriodicalTrigger and fix '0' case error | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT While taking a peek at the code I found the possibility for this case slipping by the error checking. To prevent code duplication I took the liberty to also merge the two checks since they are so similar. Please let me know if there is any feedback on my pull request or if there are any questions. Commits ------- 14f827b Add test for 0 and '0' in PeriodicalTrigger Fix '0' case error and remove duplicate code
2 parents 1dcdb66 + 14f827b commit 7be1c03

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/Symfony/Component/Scheduler/Tests/Trigger/PeriodicalTriggerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public static function getInvalidIntervals(): iterable
7373
yield ['3600.5'];
7474
yield ['-3600'];
7575
yield [-3600];
76+
yield ['0'];
77+
yield [0];
7678
}
7779

7880
/**

src/Symfony/Component/Scheduler/Trigger/PeriodicalTrigger.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,11 @@ public function __construct(
3030
$this->from = \is_string($from) ? new \DateTimeImmutable($from) : $from;
3131
$this->until = \is_string($until) ? new \DateTimeImmutable($until) : $until;
3232

33-
if (\is_int($interval) || \is_float($interval)) {
34-
if (0 >= $interval) {
33+
if (\is_int($interval) || \is_float($interval) || \is_string($interval) && ctype_digit($interval)) {
34+
if (0 >= (int) $interval) {
3535
throw new InvalidArgumentException('The "$interval" argument must be greater than zero.');
3636
}
3737

38-
$this->intervalInSeconds = $interval;
39-
$this->description = sprintf('every %d seconds', $this->intervalInSeconds);
40-
41-
return;
42-
}
43-
44-
if (\is_string($interval) && ctype_digit($interval)) {
4538
$this->intervalInSeconds = (int) $interval;
4639
$this->description = sprintf('every %d seconds', $this->intervalInSeconds);
4740

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy