Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
2 / 4 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| TaskFactory | |
50.00% |
2 / 4 |
|
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 1 |
| create | |
50.00% |
2 / 4 |
|
0.00% |
0 / 1 |
6.00 | |||
| 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\System\OperatingSystem; |
| 18 | use phpOMS\System\SystemType; |
| 19 | |
| 20 | /** |
| 21 | * Task factory. |
| 22 | * |
| 23 | * @package phpOMS\Utils\TaskSchedule |
| 24 | * @license OMS License 2.0 |
| 25 | * @link https://jingga.app |
| 26 | * @since 1.0.0 |
| 27 | */ |
| 28 | final class TaskFactory |
| 29 | { |
| 30 | /** |
| 31 | * Create task instance. |
| 32 | * |
| 33 | * @param string $id Task id |
| 34 | * @param string $cmd Command to run |
| 35 | * |
| 36 | * @return TaskAbstract |
| 37 | * |
| 38 | * @throws \Exception This exception is thrown if the operating system is not supported |
| 39 | * |
| 40 | * @since 1.0.0 |
| 41 | */ |
| 42 | public static function create(string $id = '', string $cmd = '') : TaskAbstract |
| 43 | { |
| 44 | switch (OperatingSystem::getSystem()) { |
| 45 | case SystemType::WIN: |
| 46 | return new Schedule($id, $cmd); |
| 47 | case SystemType::LINUX: |
| 48 | return new CronJob($id, $cmd); |
| 49 | default: |
| 50 | throw new \Exception('Unsupported system.'); |
| 51 | } |
| 52 | } |
| 53 | } |