Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
18.75% |
3 / 16 |
|
14.29% |
1 / 7 |
CRAP | |
0.00% |
0 / 1 |
| Module | |
18.75% |
3 / 16 |
|
14.29% |
1 / 7 |
42.33 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setStatus | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| __toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toArray | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package Modules\Admin\Models |
| 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 Modules\Admin\Models; |
| 16 | |
| 17 | use phpOMS\Module\ModuleStatus; |
| 18 | use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; |
| 19 | |
| 20 | /** |
| 21 | * Module class. |
| 22 | * |
| 23 | * @package Modules\Admin\Models |
| 24 | * @license OMS License 2.0 |
| 25 | * @link https://jingga.app |
| 26 | * @since 1.0.0 |
| 27 | */ |
| 28 | class Module |
| 29 | { |
| 30 | /** |
| 31 | * Module id. |
| 32 | * |
| 33 | * @var string |
| 34 | * @since 1.0.0 |
| 35 | */ |
| 36 | public string $id = ''; |
| 37 | |
| 38 | /** |
| 39 | * Module name. |
| 40 | * |
| 41 | * @var string |
| 42 | * @since 1.0.0 |
| 43 | */ |
| 44 | public string $name = ''; |
| 45 | |
| 46 | /** |
| 47 | * Module path. |
| 48 | * |
| 49 | * @var string |
| 50 | * @since 1.0.0 |
| 51 | */ |
| 52 | public string $path = ''; |
| 53 | |
| 54 | /** |
| 55 | * Module version. |
| 56 | * |
| 57 | * @var string |
| 58 | * @since 1.0.0 |
| 59 | */ |
| 60 | public string $version = ''; |
| 61 | |
| 62 | /** |
| 63 | * Module theme. |
| 64 | * |
| 65 | * @var string |
| 66 | * @since 1.0.0 |
| 67 | */ |
| 68 | public string $theme = ''; |
| 69 | |
| 70 | /** |
| 71 | * Group status. |
| 72 | * |
| 73 | * @var int |
| 74 | * @since 1.0.0 |
| 75 | */ |
| 76 | public int $status = ModuleStatus::INACTIVE; |
| 77 | |
| 78 | /** |
| 79 | * Created at. |
| 80 | * |
| 81 | * @var \DateTimeImmutable |
| 82 | * @since 1.0.0 |
| 83 | */ |
| 84 | public \DateTimeImmutable $createdAt; |
| 85 | |
| 86 | /** |
| 87 | * Constructor. |
| 88 | * |
| 89 | * @since 1.0.0 |
| 90 | */ |
| 91 | public function __construct() |
| 92 | { |
| 93 | $this->createdAt = new \DateTimeImmutable('now'); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Get module id. |
| 98 | * |
| 99 | * @return string |
| 100 | * |
| 101 | * @since 1.0.0 |
| 102 | */ |
| 103 | public function getId() : string |
| 104 | { |
| 105 | return $this->id; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Get module status. |
| 110 | * |
| 111 | * @return int Module status |
| 112 | * |
| 113 | * @since 1.0.0 |
| 114 | */ |
| 115 | public function getStatus() : int |
| 116 | { |
| 117 | return $this->status; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Set module status. |
| 122 | * |
| 123 | * @param int $status Module status |
| 124 | * |
| 125 | * @return void |
| 126 | * |
| 127 | * @throws InvalidEnumValue |
| 128 | * |
| 129 | * @since 1.0.0 |
| 130 | */ |
| 131 | public function setStatus(int $status) : void |
| 132 | { |
| 133 | if (!ModuleStatusUpdateType::isValidValue($status)) { |
| 134 | throw new InvalidEnumValue($status); |
| 135 | } |
| 136 | |
| 137 | $this->status = $status; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Get string representation. |
| 142 | * |
| 143 | * @return string |
| 144 | * |
| 145 | * @since 1.0.0 |
| 146 | */ |
| 147 | public function __toString() |
| 148 | { |
| 149 | return (string) \json_encode($this->toArray()); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * {@inheritdoc} |
| 154 | */ |
| 155 | public function jsonSerialize() : mixed |
| 156 | { |
| 157 | return $this->toArray(); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * {@inheritdoc} |
| 162 | */ |
| 163 | public function toArray() : array |
| 164 | { |
| 165 | return [ |
| 166 | 'id' => $this->id, |
| 167 | 'name' => $this->name, |
| 168 | 'path' => $this->path, |
| 169 | 'version' => $this->version, |
| 170 | 'status' => $this->status, |
| 171 | 'createdAt' => $this->createdAt, |
| 172 | ]; |
| 173 | } |
| 174 | } |