Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
14 / 14
CRAP
100.00% covered (success)
100.00%
1 / 1
TaskAbstract
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
14 / 14
14
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
n/a
0 / 0
n/a
0 / 0
0
 getCommand
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setCommand
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getInterval
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setInterval
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStatus
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setStatus
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNextRunTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setNextRunTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLastRuntime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLastRuntime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getComment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setComment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createWith
n/a
0 / 0
n/a
0 / 0
0
1<?php
2/**
3 * Jingga
4 *
5 * PHP Version 8.1
6 *
7 * @package   phpOMS\Utils\TaskSchedule
8 * @copyright Dennis Eichhorn
9 * @license   OMS License 2.0
10 * @version   1.0.0
11 * @link      https://jingga.app
12 */
13declare(strict_types=1);
14
15namespace phpOMS\Utils\TaskSchedule;
16
17/**
18 * Abstract task class.
19 *
20 * @package phpOMS\Utils\TaskSchedule
21 * @license OMS License 2.0
22 * @link    https://jingga.app
23 * @since   1.0.0
24 */
25abstract class TaskAbstract
26{
27    /**
28     * Id.
29     *
30     * @var string
31     * @since 1.0.0
32     */
33    public string $id = '';
34
35    /**
36     * Command used for creating the task
37     *
38     * @var string
39     * @since 1.0.0
40     */
41    public string $command = '';
42
43    /**
44     * Run interval
45     *
46     * @var string
47     * @since 1.0.0
48     */
49    public string $interval = '';
50
51    /**
52     * Status of the task
53     *
54     * @var int
55     * @since 1.0.0
56     */
57    protected int $status = TaskStatus::ACTIVE;
58
59    /**
60     * Next runtime
61     *
62     * @var \DateTime
63     * @since 1.0.0
64     */
65    protected \DateTime $nextRunTime;
66
67    /**
68     * Last runtime
69     *
70     * @var \DateTime
71     * @since 1.0.0
72     */
73    protected \DateTime $lastRunTime;
74
75    /**
76     * Comment
77     *
78     * @var string
79     * @since 1.0.0
80     */
81    public string $comment = '';
82
83    /**
84     * Constructor
85     *
86     * @param string $name Id/name of the task (on linux the same as the executable script)
87     * @param string $cmd  Command to create the task
88     *
89     * @since 1.0.0
90     */
91    public function __construct(string $name, string $cmd = '', string $interval = '')
92    {
93        $this->id          = $name;
94        $this->command     = $cmd;
95        $this->interval    = $interval;
96        $this->lastRunTime = new \DateTime('1900-01-01');
97        $this->nextRunTime = new \DateTime('1900-01-01');
98    }
99
100    /**
101     * Get id.
102     *
103     * @return string
104     *
105     * @since 1.0.0
106     */
107    public function getId() : string
108    {
109        return $this->id;
110    }
111
112    /**
113     * Stringify task for direct handling
114     *
115     * @return string
116     *
117     * @since 1.0.0
118     */
119    abstract public function __toString() : string;
120
121    /**
122     * Get command to create the task
123     *
124     * @return string
125     *
126     * @since 1.0.0
127     */
128    public function getCommand() : string
129    {
130        return $this->command;
131    }
132
133    /**
134     * Set command to create the task
135     *
136     * @param string $command Command
137     *
138     * @return void
139     *
140     * @since 1.0.0
141     */
142    public function setCommand(string $command) : void
143    {
144        $this->command = $command;
145    }
146
147    /**
148     * Get interval to create the task
149     *
150     * @return string
151     *
152     * @since 1.0.0
153     */
154    public function getInterval() : string
155    {
156        return $this->interval;
157    }
158
159    /**
160     * Set interval to create the task
161     *
162     * @param string $interval Interval
163     *
164     * @return void
165     *
166     * @since 1.0.0
167     */
168    public function setInterval(string $interval) : void
169    {
170        $this->interval = $interval;
171    }
172
173    /**
174     * Get status.
175     *
176     * @return int
177     *
178     * @since 1.0.0
179     */
180    public function getStatus() : int
181    {
182        return $this->status;
183    }
184
185    /**
186     * Set status.
187     *
188     * @param int $status Status
189     *
190     * @return void
191     *
192     * @since 1.0.0
193     */
194    public function setStatus(int $status) : void
195    {
196        $this->status = $status;
197    }
198
199    /**
200     * Get next run time.
201     *
202     * @return \DateTime
203     *
204     * @since 1.0.0
205     */
206    public function getNextRunTime() : \DateTime
207    {
208        return $this->nextRunTime;
209    }
210
211    /**
212     * Set next run time.
213     *
214     * @param \DateTime $nextRunTime Next run time
215     *
216     * @return void
217     *
218     * @since 1.0.0
219     */
220    public function setNextRunTime(\DateTime $nextRunTime) : void
221    {
222        $this->nextRunTime = $nextRunTime;
223    }
224
225    /**
226     * Get last run time.
227     *
228     * @return \DateTime
229     *
230     * @since 1.0.0
231     */
232    public function getLastRuntime() : \DateTime
233    {
234        return $this->lastRunTime;
235    }
236
237    /**
238     * Set last run time.
239     *
240     * @param \DateTime $lastRunTime Last run time
241     *
242     * @return void
243     *
244     * @since 1.0.0
245     */
246    public function setLastRuntime(\DateTime $lastRunTime) : void
247    {
248        $this->lastRunTime = $lastRunTime;
249    }
250
251    /**
252     * Get comment.
253     *
254     * @return string
255     *
256     * @since 1.0.0
257     */
258    public function getComment() : string
259    {
260        return $this->comment;
261    }
262
263    /**
264     * Set comment.
265     *
266     * @param string $comment Comment
267     *
268     * @return void
269     *
270     * @since 1.0.0
271     */
272    public function setComment(string $comment) : void
273    {
274        $this->comment = $comment;
275    }
276
277    /**
278     * Create task based on job data
279     *
280     * @param array $jobData Raw job data
281     *
282     * @return TaskAbstract
283     *
284     * @since 1.0.0
285     */
286    abstract public static function createWith(array $jobData) : self;
287}