From f52c50660a9420c0a10423596624d42819dd371e Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sun, 17 Nov 2024 09:45:56 +0100 Subject: [PATCH] update stan --- .phive/phars.xml | 4 +- phpstan.neon | 5 +- src/Scheduler/Scheduler.php | 6 +- src/Scheduler/Traits/FrequenciesTrait.php | 2 +- tests/TestCase/Scheduler/EventTest.php | 66 +++++++++++----------- tests/TestCase/Scheduler/SchedulerTest.php | 2 +- 6 files changed, 46 insertions(+), 39 deletions(-) diff --git a/.phive/phars.xml b/.phive/phars.xml index bca1406..1234f00 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon index 8c2eb0d..ff6d291 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,6 +2,9 @@ parameters: paths: - src - tests/TestCase - level: 5 + level: 8 bootstrapFiles: - tests/bootstrap.php + ignoreErrors: + - + identifier: missingType.iterableValue diff --git a/src/Scheduler/Scheduler.php b/src/Scheduler/Scheduler.php index 5951f15..0e8cdc8 100644 --- a/src/Scheduler/Scheduler.php +++ b/src/Scheduler/Scheduler.php @@ -50,7 +50,11 @@ public function __construct(?Container $container = null) public function execute(string $command, array $args = []): Event { try { - $commandObj = $this->container->get($command); + if ($this->container !== null) { + $commandObj = $this->container->get($command); + } elseif (class_exists($command)) { + $commandObj = new $command(); + } } catch (ContainerExceptionInterface | NotFoundExceptionInterface $ex) { if (class_exists($command)) { $commandObj = new $command(); diff --git a/src/Scheduler/Traits/FrequenciesTrait.php b/src/Scheduler/Traits/FrequenciesTrait.php index 750a740..cbe2ff8 100644 --- a/src/Scheduler/Traits/FrequenciesTrait.php +++ b/src/Scheduler/Traits/FrequenciesTrait.php @@ -328,7 +328,7 @@ public function days(int|string|array $days): self */ protected function spliceIntoPosition(int $position, mixed $value): self { - $segments = preg_split("/\s+/", $this->expression); + $segments = preg_split("/\s+/", $this->expression) ?: []; $segments[$position - 1] = $value; diff --git a/tests/TestCase/Scheduler/EventTest.php b/tests/TestCase/Scheduler/EventTest.php index ba9ac80..f72c6dc 100644 --- a/tests/TestCase/Scheduler/EventTest.php +++ b/tests/TestCase/Scheduler/EventTest.php @@ -26,53 +26,53 @@ public function testIsDue(): void Chronos::setTestNow('now'); } - public function testEveryMinute() + public function testEveryMinute(): void { $this->assertSame('* * * * *', $this->event->getExpression()); $this->assertSame('* * * * *', $this->event->everyMinute()->getExpression()); } - public function testEveryXMinutes() + public function testEveryXMinutes(): void { $this->assertSame('*/2 * * * *', $this->event->everyXMinutes(2)->getExpression()); $this->expectException(InvalidArgumentException::class); $this->assertSame('*/2 * * * *', $this->event->everyXMinutes(-10)->getExpression()); } - public function testDaily() + public function testDaily(): void { $this->assertSame('0 0 * * *', $this->event->daily()->getExpression()); } - public function testDailyAt() + public function testDailyAt(): void { $this->assertSame('8 13 * * *', $this->event->dailyAt('13:08')->getExpression()); } - public function testTwiceDailyAt() + public function testTwiceDailyAt(): void { $this->assertSame('0 3,15 * * *', $this->event->twiceDailyAt(3, 15)->getExpression()); $this->assertSame('5 3,15 * * *', $this->event->twiceDailyAt(3, 15, 5)->getExpression()); } - public function testWeekly() + public function testWeekly(): void { $this->assertSame('0 0 * * 0', $this->event->weekly()->getExpression()); } - public function testWeeklyOn() + public function testWeeklyOn(): void { $this->assertSame('0 8 * * 1', $this->event->weeklyOn(Event::MONDAY, '8:00')->getExpression()); } - public function testOverrideWithHourly() + public function testOverrideWithHourly(): void { $this->assertSame('0 * * * *', $this->event->everyXMinutes(5)->hourly()->getExpression()); $this->assertSame('37 * * * *', $this->event->hourlyAt(37)->getExpression()); $this->assertSame('15,30,45 * * * *', $this->event->hourlyAt([15, 30, 45])->getExpression()); } - public function testHourly() + public function testHourly(): void { $this->assertSame('0 1-23/2 * * *', $this->event->everyOddHour()->getExpression()); $this->assertSame('0 */2 * * *', $this->event->everyXHours(2)->getExpression()); @@ -80,125 +80,125 @@ public function testHourly() $this->assertSame('*/2 * * * *', $this->event->everyXHours(-10)->getExpression()); } - public function testMonthly() + public function testMonthly(): void { $this->assertSame('0 0 1 * *', $this->event->monthly()->getExpression()); } - public function testMonthlyOn() + public function testMonthlyOn(): void { $this->assertSame('0 15 4 * *', $this->event->monthlyOn(4, '15:00')->getExpression()); } - public function testLastDayOfMonth() + public function testLastDayOfMonth(): void { Chronos::setTestNow('2020-10-10 10:10:10'); $this->assertSame('0 0 31 * *', $this->event->lastDayOfMonth()->getExpression()); Chronos::setTestNow('now'); } - public function testTwiceMonthly() + public function testTwiceMonthly(): void { $this->assertSame('0 0 1,16 * *', $this->event->twiceMonthly(1, 16)->getExpression()); } - public function testTwiceMonthlyAtTime() + public function testTwiceMonthlyAtTime(): void { $this->assertSame('30 1 1,16 * *', $this->event->twiceMonthly(1, 16, '1:30')->getExpression()); } - public function testMonthlyOnWithMinutes() + public function testMonthlyOnWithMinutes(): void { $this->assertSame('15 15 4 * *', $this->event->monthlyOn(4, '15:15')->getExpression()); } - public function testWeekdaysDaily() + public function testWeekdaysDaily(): void { $this->assertSame('0 0 * * 1-5', $this->event->weekdays()->daily()->getExpression()); } - public function testWeekdaysHourly() + public function testWeekdaysHourly(): void { $this->assertSame('0 * * * 1-5', $this->event->weekdays()->hourly()->getExpression()); } - public function testWeekdays() + public function testWeekdays(): void { $this->assertSame('* * * * 1-5', $this->event->weekdays()->getExpression()); } - public function testWeekends() + public function testWeekends(): void { $this->assertSame('* * * * 6,0', $this->event->weekends()->getExpression()); } - public function testSundays() + public function testSundays(): void { $this->assertSame('* * * * 0', $this->event->sundays()->getExpression()); } - public function testMondays() + public function testMondays(): void { $this->assertSame('* * * * 1', $this->event->mondays()->getExpression()); } - public function testTuesdays() + public function testTuesdays(): void { $this->assertSame('* * * * 2', $this->event->tuesdays()->getExpression()); } - public function testWednesdays() + public function testWednesdays(): void { $this->assertSame('* * * * 3', $this->event->wednesdays()->getExpression()); } - public function testThursdays() + public function testThursdays(): void { $this->assertSame('* * * * 4', $this->event->thursdays()->getExpression()); } - public function testFridays() + public function testFridays(): void { $this->assertSame('* * * * 5', $this->event->fridays()->getExpression()); } - public function testSaturdays() + public function testSaturdays(): void { $this->assertSame('* * * * 6', $this->event->saturdays()->getExpression()); } - public function testDays() + public function testDays(): void { $this->assertSame('* * * * 1', $this->event->days(Event::MONDAY)->getExpression()); $this->assertSame('* * * * 1,4', $this->event->days([Event::MONDAY, Event::THURSDAY])->getExpression()); } - public function testQuarterly() + public function testQuarterly(): void { $this->assertSame('0 0 1 1-12/3 *', $this->event->quarterly()->getExpression()); } - public function testQuarterlyOn() + public function testQuarterlyOn(): void { $this->assertSame('0 0 2 1-12/3 *', $this->event->quarterlyOn(2)->getExpression()); } - public function testYearly() + public function testYearly(): void { $this->assertSame('0 0 1 1 *', $this->event->yearly()->getExpression()); } - public function testYearlyOn() + public function testYearlyOn(): void { $this->assertSame('8 15 5 4 *', $this->event->yearlyOn(4, '5', '15:08')->getExpression()); } - public function testYearlyOnMondaysOnly() + public function testYearlyOnMondaysOnly(): void { $this->assertSame('1 9 * 7 1', $this->event->mondays()->yearlyOn(7, '*', '09:01')->getExpression()); } - public function testYearlyOnTuesdaysAndDayOfMonth20() + public function testYearlyOnTuesdaysAndDayOfMonth20(): void { $this->assertSame('1 9 20 7 2', $this->event->tuesdays()->yearlyOn(7, '20', '09:01')->getExpression()); } diff --git a/tests/TestCase/Scheduler/SchedulerTest.php b/tests/TestCase/Scheduler/SchedulerTest.php index b7d8102..97d0b0b 100644 --- a/tests/TestCase/Scheduler/SchedulerTest.php +++ b/tests/TestCase/Scheduler/SchedulerTest.php @@ -33,7 +33,7 @@ public function testAddDueEvents(): void { $this->scheduler->execute(VersionCommand::class); $events = $this->scheduler->dueEvents(); - $this->assertNotEmpty($events); + $this->assertFalse($events->isEmpty()); } public function testAddMultipleDueEvents(): void