Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| CategoryView | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| of | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Expense\Application\Query; |
| 6 | |
| 7 | use App\Expense\Domain\Category; |
| 8 | use App\Expense\Domain\CategorySetting; |
| 9 | |
| 10 | /** |
| 11 | * The wire shape of a category: the enum's defaults with the admin overlay |
| 12 | * merged on top. No row (null setting) → the code defaults, active. |
| 13 | * |
| 14 | * ponytail: one shape for both the app's /categories and the admin listing — |
| 15 | * the app ignores `active` because it only ever receives active ones. |
| 16 | */ |
| 17 | final class CategoryView |
| 18 | { |
| 19 | /** @return array{value: string, label: string, icon: string, color: string, active: bool} */ |
| 20 | public static function of(Category $category, ?CategorySetting $setting): array |
| 21 | { |
| 22 | return [ |
| 23 | 'value' => $category->value, |
| 24 | 'label' => $setting?->label() ?? $category->label(), |
| 25 | 'icon' => $setting?->icon() ?? $category->icon(), |
| 26 | 'color' => $setting?->color() ?? $category->color(), |
| 27 | 'active' => $setting?->isActive() ?? true, |
| 28 | ]; |
| 29 | } |
| 30 | } |