Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
47.62% |
10 / 21 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SystemSettingData | |
47.62% |
10 / 21 |
|
0.00% |
0 / 3 |
11.17 | |
0.00% |
0 / 1 |
| __construct | |
90.91% |
10 / 11 |
|
0.00% |
0 / 1 |
4.01 | |||
| getValue | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Domain\SystemSettings\Data; |
| 6 | |
| 7 | use JsonSerializable; |
| 8 | |
| 9 | /** |
| 10 | * Data transfer object for system settings. |
| 11 | */ |
| 12 | final class SystemSettingData implements JsonSerializable |
| 13 | { |
| 14 | public int $settingId; |
| 15 | |
| 16 | public string $settingKey; |
| 17 | |
| 18 | /** @var array<string, mixed> */ |
| 19 | public array $settingValue; |
| 20 | |
| 21 | public ?string $description; |
| 22 | |
| 23 | public ?int $updatedBy; |
| 24 | |
| 25 | public string $createdAt; |
| 26 | |
| 27 | public string $updatedAt; |
| 28 | |
| 29 | /** |
| 30 | * @param array<string, mixed> $data |
| 31 | */ |
| 32 | public function __construct(array $data) |
| 33 | { |
| 34 | $this->settingId = (int)$data['settingId']; |
| 35 | $this->settingKey = $data['settingKey']; |
| 36 | |
| 37 | // Handle JSONB - might be string or already decoded |
| 38 | $value = $data['settingValue']; |
| 39 | if (is_string($value)) { |
| 40 | $decoded = json_decode($value, true); |
| 41 | $this->settingValue = is_array($decoded) ? $decoded : ['value' => $value]; |
| 42 | } else { |
| 43 | $this->settingValue = (array)$value; |
| 44 | } |
| 45 | |
| 46 | $this->description = $data['description'] ?? null; |
| 47 | $this->updatedBy = isset($data['updatedBy']) ? (int)$data['updatedBy'] : null; |
| 48 | $this->createdAt = $data['createdAt']; |
| 49 | $this->updatedAt = $data['updatedAt']; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get the primary value from the JSONB setting. |
| 54 | */ |
| 55 | public function getValue(): mixed |
| 56 | { |
| 57 | return $this->settingValue['value'] ?? null; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return array<string, mixed> |
| 62 | */ |
| 63 | public function jsonSerialize(): array |
| 64 | { |
| 65 | return [ |
| 66 | 'settingId' => $this->settingId, |
| 67 | 'settingKey' => $this->settingKey, |
| 68 | 'settingValue' => $this->settingValue, |
| 69 | 'description' => $this->description, |
| 70 | 'updatedBy' => $this->updatedBy, |
| 71 | 'createdAt' => $this->createdAt, |
| 72 | 'updatedAt' => $this->updatedAt, |
| 73 | ]; |
| 74 | } |
| 75 | } |