Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Schedule | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
5.03 | |
0.00% |
0 / 1 |
| __toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| createWith | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
3.02 | |||
| 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 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Utils\TaskSchedule; |
| 16 | |
| 17 | use phpOMS\Validation\Base\DateTime; |
| 18 | |
| 19 | /** |
| 20 | * Schedule class. |
| 21 | * |
| 22 | * @package phpOMS\Utils\TaskSchedule |
| 23 | * @license OMS License 2.0 |
| 24 | * @link https://jingga.app |
| 25 | * @since 1.0.0 |
| 26 | */ |
| 27 | class Schedule extends TaskAbstract |
| 28 | { |
| 29 | /** |
| 30 | * {@inheritdoc} |
| 31 | */ |
| 32 | public function __toString() : string |
| 33 | { |
| 34 | return $this->interval === '' ? '' : '/tn ' . $this->id . ' ' . $this->interval . ' ' . $this->command; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * {@inheritdoc} |
| 39 | */ |
| 40 | public static function createWith(array $jobData) : TaskAbstract |
| 41 | { |
| 42 | /** |
| 43 | * @todo Karaka/phpOMS#231 |
| 44 | * Use the interval for generating a schedule |
| 45 | */ |
| 46 | $job = new self($jobData[1], $jobData[8], $jobData[7]); |
| 47 | |
| 48 | $job->setStatus((int) $jobData[3]); |
| 49 | |
| 50 | if (DateTime::isValid($jobData[2])) { |
| 51 | $job->setNextRunTime(new \DateTime($jobData[2])); |
| 52 | } |
| 53 | |
| 54 | if (DateTime::isValid($jobData[5])) { |
| 55 | $job->setLastRuntime(new \DateTime($jobData[5])); |
| 56 | } |
| 57 | |
| 58 | $job->setComment($jobData[10] ?? ''); |
| 59 | |
| 60 | return $job; |
| 61 | } |
| 62 | } |