Skip to content

Commit

Permalink
[CHANGE] Updated dependency requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoHaase committed Dec 6, 2023
1 parent d971436 commit c4ba310
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 108 deletions.
33 changes: 12 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 2 additions & 5 deletions Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -70,6 +67,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$table->render();

return 0;
return self::SUCCESS;
}
}
15 changes: 6 additions & 9 deletions Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,10 +17,7 @@

class RunCommand extends Command
{
/**
* @var Scheduler
*/
private $scheduler;
private Scheduler $scheduler;

public function __construct(Scheduler $scheduler)
{
Expand All @@ -42,29 +40,28 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$id = $input->getArgument("id");
$class = $input->getOption("class");


if (!$id && !$class) {
$this->scheduler->run();
} elseif ($class) {
$tasks = $this->scheduler->getTasks();
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;
}
}
9 changes: 1 addition & 8 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
6 changes: 3 additions & 3 deletions Services/SchedulerLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 1 addition & 7 deletions Task/AbstractScheduledTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@

abstract class AbstractScheduledTask implements TaskInterface
{
/**
* @var Schedule
*/
private $schedule;
private Schedule $schedule;

public function __construct()
{
Expand All @@ -32,9 +29,6 @@ public function isDue($currentTime): bool
return $this->schedule->isDue($currentTime);
}

/**
* @return Schedule
*/
public function getSchedule(): Schedule
{
return $this->schedule;
Expand Down
31 changes: 1 addition & 30 deletions Task/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
*/
class Schedule
{
/**
* @var CronExpression
*/
private $cron;
private CronExpression $cron;

/**
* Schedule constructor.
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -72,7 +66,6 @@ public function daysOfMonth($days): self

/**
* Sets the cron to work every day
* @return $this
*/
public function daily(): self
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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();
Expand All @@ -161,20 +140,13 @@ 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
{
$this->cron->setExpression($value);
return $this;
}

/**
* @param int $position
* @param string $value
* @return $this
*/
public function setPart(int $position, string $value): self
{
$this->cron->setPart($position, $value);
Expand All @@ -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
{
Expand Down
17 changes: 1 addition & 16 deletions Task/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@

class Scheduler
{
/**
* @var EventDispatcher
*/
private $dispatcher;
private EventDispatcher $dispatcher;

public function __construct(EventDispatcher $dispatcher = null)
{
Expand All @@ -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);
Expand All @@ -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]);
Expand Down
2 changes: 0 additions & 2 deletions Task/TaskInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit c4ba310

Please sign in to comment.