diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cf292c9..510ffcf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,32 +15,23 @@ jobs: strategy: matrix: php-version: - - "7.2" - - "7.3" - "7.4" - - "8.0" - "8.1" + - "8.2" + - "8.3" symfony-version: - - "3.4.x" - - "4.4.x" - - "5.3.x" - "5.4.x" + - "6.4.x" + - "7.0.x" monolog-version: - - "^1.25" - - "^2.2" - include: - - php-version: "8.0" - symfony-version: "6.0.x" - monolog-version: "^1.25" - - php-version: "8.1" - symfony-version: "6.0.x" - monolog-version: "^1.25" - - php-version: "8.0" - symfony-version: "6.0.x" - monolog-version: "^2.2" - - php-version: "8.1" - symfony-version: "6.0.x" - monolog-version: "^2.2" + - "^2.9" + exclude: + - php-version: "7.4" + symfony-version: "6.4.x" + - php-version: "7.4" + symfony-version: "7.0.x" + - php-version: "8.1" + symfony-version: "7.0.x" steps: - name: "Checkout" diff --git a/Command/ListCommand.php b/Command/ListCommand.php index af00a55..8e8b3dd 100644 --- a/Command/ListCommand.php +++ b/Command/ListCommand.php @@ -17,10 +17,7 @@ class ListCommand extends Command { private const NUMBER_OF_RUN_DATES = 3; - /** - * @var Scheduler - */ - private $scheduler; + private Scheduler $scheduler; public function __construct(Scheduler $scheduler) { @@ -70,6 +67,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $table->render(); - return 0; + return self::SUCCESS; } } diff --git a/Command/RunCommand.php b/Command/RunCommand.php index 6ed91fb..f6a9f1c 100644 --- a/Command/RunCommand.php +++ b/Command/RunCommand.php @@ -7,6 +7,7 @@ namespace Rewieer\TaskSchedulerBundle\Command; +use Exception; use Rewieer\TaskSchedulerBundle\Task\Scheduler; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -16,10 +17,7 @@ class RunCommand extends Command { - /** - * @var Scheduler - */ - private $scheduler; + private Scheduler $scheduler; public function __construct(Scheduler $scheduler) { @@ -42,7 +40,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $id = $input->getArgument("id"); $class = $input->getOption("class"); - if (!$id && !$class) { $this->scheduler->run(); } elseif ($class) { @@ -50,21 +47,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int foreach ($tasks as $task) { if (strpos(get_class($task), "\\$class")) { $this->scheduler->runTask($task); - return 0; + return self::SUCCESS; } } - throw new \Exception("There are no tasks corresponding to this class name"); + throw new Exception("There are no tasks corresponding to this class name"); } else { $tasks = $this->scheduler->getTasks(); $id = (int)$id; if (array_key_exists($id - 1, $tasks) === false) { - throw new \Exception("There are no tasks corresponding to this ID"); + throw new Exception("There are no tasks corresponding to this ID"); } $this->scheduler->runTask($tasks[$id - 1]); } - return 0; + return self::SUCCESS; } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 2edcbc6..e772d63 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -20,13 +20,6 @@ class Configuration implements ConfigurationInterface { public function getConfigTreeBuilder(): TreeBuilder { - $treeBuilder = new TreeBuilder('rewieer_task_scheduler'); - - if (false === \method_exists($treeBuilder, 'getRootNode')) { - // BC layer for symfony/config 4.1 and older - $treeBuilder->root('rewieer_task_scheduler'); - } - - return $treeBuilder; + return new TreeBuilder('rewieer_task_scheduler'); } } diff --git a/Services/SchedulerLogger.php b/Services/SchedulerLogger.php index c1541be..710f37b 100644 --- a/Services/SchedulerLogger.php +++ b/Services/SchedulerLogger.php @@ -21,9 +21,9 @@ */ class SchedulerLogger implements EventSubscriberInterface { - private $logger; - private $start; - private $current; + private LoggerInterface $logger; + private ?float $start; + private ?float $current; public function __construct(LoggerInterface $logger) { diff --git a/Task/AbstractScheduledTask.php b/Task/AbstractScheduledTask.php index 3f562bd..68b27dc 100644 --- a/Task/AbstractScheduledTask.php +++ b/Task/AbstractScheduledTask.php @@ -12,10 +12,7 @@ abstract class AbstractScheduledTask implements TaskInterface { - /** - * @var Schedule - */ - private $schedule; + private Schedule $schedule; public function __construct() { @@ -32,9 +29,6 @@ public function isDue($currentTime): bool return $this->schedule->isDue($currentTime); } - /** - * @return Schedule - */ public function getSchedule(): Schedule { return $this->schedule; diff --git a/Task/Schedule.php b/Task/Schedule.php index 6c262b2..06e380f 100644 --- a/Task/Schedule.php +++ b/Task/Schedule.php @@ -19,10 +19,7 @@ */ class Schedule { - /** - * @var CronExpression - */ - private $cron; + private CronExpression $cron; /** * Schedule constructor. @@ -36,7 +33,6 @@ public function __construct(string $expr = "* * * * *") /** * Sets the cron to work at these months * @param string|int $months - * @return $this */ public function months($months): self { @@ -48,7 +44,6 @@ public function months($months): self * Sets the cron to work at these days of the week * ATTENTION: resets daysOfMonth * @param string|int $days - * @return $this */ public function daysOfWeek($days): self { @@ -61,7 +56,6 @@ public function daysOfWeek($days): self * Sets the cron to work at these days of the month * ATTENTION: resets daysOfWeek * @param string|int $days - * @return $this */ public function daysOfMonth($days): self { @@ -72,7 +66,6 @@ public function daysOfMonth($days): self /** * Sets the cron to work every day - * @return $this */ public function daily(): self { @@ -83,7 +76,6 @@ public function daily(): self /** * Set the cron to work at these hours * @param string|int $hours - * @return $this */ public function hours($hours): self { @@ -94,7 +86,6 @@ public function hours($hours): self /** * Set the cron to work at these minutes * @param string|int $minutes - * @return $this */ public function minutes($minutes): self { @@ -105,7 +96,6 @@ public function minutes($minutes): self /** * Set the cron to work at every x minutes * @param int $minutes - * @return $this */ public function everyMinutes(int $minutes = 1): self { @@ -115,7 +105,6 @@ public function everyMinutes(int $minutes = 1): self /** * Set the cron to work at every x hours * @param int $hours - * @return $this */ public function everyHours(int $hours = 1): self { @@ -125,10 +114,6 @@ public function everyHours(int $hours = 1): self /** * Generic function to update a cron part as an "everyX" pattern * such as "every 3 hours" or "every 10 minutes" - * - * @param int $time - * @param int $part - * @return $this */ public function everyX(int $time = 1, int $part = CronExpression::MINUTE): self { @@ -142,17 +127,11 @@ public function everyX(int $time = 1, int $part = CronExpression::MINUTE): self return $this; } - /** - * @return CronExpression - */ public function getCron(): CronExpression { return $this->cron; } - /** - * @return string - */ public function getExpression(): string { return $this->cron->getExpression(); @@ -161,8 +140,6 @@ public function getExpression(): string /** * Allows setting entire expression in string format like "0 * 2,7,12 * 7" * Exposes CronExpressions method directly - * @param string $value - * @return $this */ public function setExpression(string $value): self { @@ -170,11 +147,6 @@ public function setExpression(string $value): self return $this; } - /** - * @param int $position - * @param string $value - * @return $this - */ public function setPart(int $position, string $value): self { $this->cron->setPart($position, $value); @@ -184,7 +156,6 @@ public function setPart(int $position, string $value): self /** * Return true if the schedule is due to now * @param DateTimeInterface|string $currentTime - * @return bool */ public function isDue($currentTime = 'now'): bool { diff --git a/Task/Scheduler.php b/Task/Scheduler.php index 99f3a16..13c8b2e 100644 --- a/Task/Scheduler.php +++ b/Task/Scheduler.php @@ -13,10 +13,7 @@ class Scheduler { - /** - * @var EventDispatcher - */ - private $dispatcher; + private EventDispatcher $dispatcher; public function __construct(EventDispatcher $dispatcher = null) { @@ -32,19 +29,11 @@ public function __construct(EventDispatcher $dispatcher = null) */ private $tasks = []; - /** - * Adds the task to the task stack - * @param TaskInterface $task - */ public function addTask(TaskInterface $task): void { $this->tasks[] = $task; } - /** - * Run due tasks - * @param DateTimeInterface|string $currentTime - */ public function run($currentTime = "now"): void { $this->dispatcher->dispatch(SchedulerEvents::ON_START); @@ -60,10 +49,6 @@ public function run($currentTime = "now"): void $this->dispatcher->dispatch(SchedulerEvents::ON_END); } - /** - * Run the task - * @param TaskInterface $task - */ public function runTask(TaskInterface $task): void { $this->dispatcher->dispatch(SchedulerEvents::BEFORE_TASK_RUNS, [$task]); diff --git a/Task/TaskInterface.php b/Task/TaskInterface.php index 808b6c7..0913746 100644 --- a/Task/TaskInterface.php +++ b/Task/TaskInterface.php @@ -15,13 +15,11 @@ interface TaskInterface /** * Return true if the task is due to now * @param DateTimeInterface|string $currentTime - * @return bool */ public function isDue($currentTime): bool; /** * Get the next run dates for this job - * @param int $counter * @return string[] */ public function getNextRunDates(int $counter): array; diff --git a/composer.json b/composer.json index af0e479..a76ce53 100644 --- a/composer.json +++ b/composer.json @@ -9,15 +9,15 @@ }, "keywords": ["cron", "task", "scheduler", "symfony", "bundle"], "require": { - "php": "^7.2|^8.0", - "symfony/framework-bundle": "^3.4|^4.4|^5.3|^6.0", - "symfony/console": "^3.4|^4.4|^5.3|^6.0", - "dragonmantank/cron-expression": "^2.3|^3.0" + "php": "^7.4|^8.1", + "symfony/framework-bundle": "^5.4|^6.4|^7.0", + "symfony/console": "^5.3|^6.4|^7.0", + "dragonmantank/cron-expression": "^3.3" }, "require-dev": { - "phpunit/phpunit": "^8.5", - "symfony/phpunit-bridge": "^5.3", - "monolog/monolog": "^1.25|^2.2" + "phpunit/phpunit": "^9.6", + "symfony/phpunit-bridge": "^6.4", + "monolog/monolog": "^2.9" }, "license": "MIT", "authors": [