Issues (29)

src/Scheduler.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of BlitzPHP Tasks.
7
 *
8
 * (c) 2025 Dimitri Sitchet Tomkeu <[email protected]>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13
14
namespace BlitzPHP\Tasks;
15
16
/**
17
 * @credit <a href="https://tasks.codeigniter.com">CodeIgniter4 - CodeIgniter\Tasks\Scheduler</a>
18
 */
19
class Scheduler
20
{
21
    public const SUNDAY    = 0;
22
    public const MONDAY    = 1;
23
    public const TUESDAY   = 2;
24
    public const WEDNESDAY = 3;
25
    public const THURSDAY  = 4;
26
    public const FRIDAY    = 5;
27
    public const SATURDAY  = 6;
28
29
    /**
30
     * @var list<Task>
0 ignored issues
show
The type BlitzPHP\Tasks\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     */
32
    protected array $tasks = [];
33
34
    /**
35
     * Renvoie les tâches créées.
36
     *
37
     * @return list<Task>
38
     */
39
    public function getTasks(): array
40
    {
41
        return $this->tasks;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->tasks returns the type array which is incompatible with the documented return type BlitzPHP\Tasks\list.
Loading history...
42
    }
43
44
    /**
45
     * Planifie l'execution d'une closure.
46
     */
47
    public function call(callable $func): Task
48
    {
49
        return $this->createTask('closure', $func);
50
    }
51
52
    /**
53
     * Planifie l'execution d'une commande.
54
     *
55
     * @param list<mixed> $parameters Parameters eventuels a transmettre aux commande.
56
     */
57
    public function command(string $command, array $parameters = []): Task
58
    {
59
        return $this->createTask('command', $command, $parameters);
60
    }
61
62
    /**
63
     * Planifie l'exécution d'une commande systeme
64
     */
65
    public function shell(string $command): Task
66
    {
67
        return $this->createTask('shell', $command);
68
    }
69
70
    /**
71
     * Planifie le declenchement d'un evenement.
72
     *
73
     * @param string $name Nom de l'evenement a declencher
74
     */
75
    public function event(string $name): Task
76
    {
77
        return $this->createTask('event', $name);
78
    }
79
80
    /**
81
     * Planifie une commande cURL vers une URL distante
82
     */
83
    public function url(string $url): Task
84
    {
85
        return $this->createTask('url', $url);
86
    }
87
88
    /**
89
     * @param mixed       $action
90
     * @param list<mixed> $parameters Parameters eventuels a transmettre aux taches.
91
     */
92
    protected function createTask(string $type, $action, array $parameters = []): Task
93
    {
94
        $task          = new Task($type, $action, $parameters);
95
        $this->tasks[] = $task;
96
97
        return $task;
98
    }
99
}
100