diff --git a/src/Commands/Lister.php b/src/Commands/Lister.php index f86b23b..98820ed 100644 --- a/src/Commands/Lister.php +++ b/src/Commands/Lister.php @@ -39,8 +39,6 @@ class Lister extends TaskCommand */ public function execute(array $params) { - helper('preference'); - if (parametre('tasks.enabled') === false) { $this->writer->error('WARNING: L\'exécution de la tâche est actuellement désactivée.', true); $this->writer->write("Pour réactiver les tâches, exécutez\u{a0}: `tasks:enable`", true); diff --git a/src/Commands/Run.php b/src/Commands/Run.php index 6add613..0f05327 100644 --- a/src/Commands/Run.php +++ b/src/Commands/Run.php @@ -49,6 +49,8 @@ public function execute(array $params) $this->writer->error('WARNING: L\'exécution de la tâche est actuellement désactivée.', true); $this->writer->write("Pour réactiver les tâches, exécutez\u{a0}: `tasks:enable`", true); $this->newLine(); + + return EXIT_ERROR; } $this->task('Exécution de tâches...')->eol(); diff --git a/src/HooksTrait.php b/src/HooksTrait.php index 735529d..9d7294d 100644 --- a/src/HooksTrait.php +++ b/src/HooksTrait.php @@ -181,9 +181,9 @@ protected function process(ContainerInterface $container, string $method): mixed { ob_start(); - $result = $this->start($this->container, $method); + $result = $this->start($container, $method); - $result = $this->finish($this->container, $result); + $result = $this->finish($container, $result); ob_end_flush(); diff --git a/src/RunResolver.php b/src/RunResolver.php index eaf2f31..28a7658 100644 --- a/src/RunResolver.php +++ b/src/RunResolver.php @@ -118,26 +118,13 @@ public function nextRun(string $expression, Date $next): Date */ protected function increment(Date $next, string $position): Date { - switch ($position) { - case 'minute': - $next = $next->addMinutes(1); - break; - - case 'hour': - $next = $next->addHours(1); - break; - - case 'monthDay': - case 'weekDay': - $next = $next->addDays(1); - break; - - case 'month': - $next = $next->addMonths(1); - break; - } - - return $next; + return match ($position) { + 'minute' => $next->addMinutes(1), + 'hour' => $next->addHours(1), + 'monthDay', 'weekDay' => $next->addDays(1), + 'month' => $next->addMonths(1), + default => $next, + }; } /** @@ -161,7 +148,7 @@ protected function isInList($value, string $list): bool { $list = explode(',', $list); - return in_array(trim($value), $list, true); + return in_array(trim((string) $value), $list, true); } /** diff --git a/src/Task.php b/src/Task.php index 0286d9e..c516e3b 100644 --- a/src/Task.php +++ b/src/Task.php @@ -57,6 +57,11 @@ class Task */ protected array $environments = []; + /** + * L'alias sous lesquel cette tâche peut être exécutée + */ + protected string $name; + /** * Faut-il empêcher les exécutions simultanées de cette tâche ? */ @@ -102,7 +107,7 @@ public function __construct(protected string $type, protected mixed $action, pro */ public function named(string $name): self { - $this->attributes['name'] = $name; + $this->name = $name; return $this; } @@ -343,7 +348,7 @@ protected function buildName(): string */ public function __get(string $key) { - if ($key === 'name' && empty($this->attributes['name'])) { + if ($key === 'name' && (! isset($this->name) || ($this->name === ''))) { return $this->buildName(); } @@ -359,7 +364,11 @@ public function __get(string $key) */ public function __set(string $name, mixed $value): void { - $this->attributes[$name] = $value; + if ($name === 'name' && (! isset($this->name) || ($this->name === ''))) { + $this->name = $value; + } else { + $this->attributes[$name] = $value; + } } /** @@ -369,7 +378,7 @@ public function __set(string $name, mixed $value): void */ private function getLockKey(): string { - $name = $this->attributes['name'] ?? $this->buildName(); + $name = $this->name ?? $this->buildName(); return 'task_lock_' . $name; } diff --git a/src/TaskRunner.php b/src/TaskRunner.php index b5f7e04..a14e789 100644 --- a/src/TaskRunner.php +++ b/src/TaskRunner.php @@ -58,11 +58,11 @@ public function run(): void foreach ($tasks as $task) { // Si des tâches spécifiques ont été choisies, sauter l'exécution des tâches restantes. - if (! empty($this->only) && ! in_array($task->name, $this->only, true)) { + if ($this->only !== [] && ! in_array($task->name, $this->only, true)) { continue; } - if (! $task->shouldRun($this->testTime) && empty($this->only)) { + if (! $task->shouldRun($this->testTime) && $this->only === []) { continue; }