Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
34 / 34 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| SpecialAccess | |
100.00% |
33 / 33 |
|
100.00% |
5 / 5 |
20 | |
100.00% |
1 / 1 |
| isValid | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| getLabel | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
6 | |||
| getIcon | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
6 | |||
| getBadgeColor | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
6 | |||
| all | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Core\Engine\Domain\Model; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * Special Access Status Specification. |
| 13 | * |
| 14 | * Defines manual access levels and lifecycle states across all CRUD modules: |
| 15 | * - 0: Hidden (Restricted strictly to superusers). |
| 16 | * - 1: Available / Visible (Default grid view tab). |
| 17 | * - 2: Archived (Archived record tab; restricted to owner/co-owners/superusers). |
| 18 | * - 3: Deleted (Soft-deleted trash tab; restricted to owner/co-owners/superusers). |
| 19 | * |
| 20 | * Modification of special access on a record is strictly restricted to superusers. |
| 21 | * |
| 22 | * @package App\Core\Engine\Domain\Model |
| 23 | */ |
| 24 | final class SpecialAccess |
| 25 | { |
| 26 | /** @var int Hidden record state (restricted strictly to superusers). */ |
| 27 | public const int HIDDEN = 0; |
| 28 | |
| 29 | /** @var int Available / Visible record state (default view tab). */ |
| 30 | public const int AVAILABLE = 1; |
| 31 | |
| 32 | /** @var int Visible alias for AVAILABLE. */ |
| 33 | public const int VISIBLE = 1; |
| 34 | |
| 35 | /** @var int Archived record state (archive tab - owner/co-owners/superusers only). */ |
| 36 | public const int ARCHIVED = 2; |
| 37 | |
| 38 | /** @var int Deleted record state (soft-deleted trash tab - owner/co-owners/superusers only). */ |
| 39 | public const int DELETED = 3; |
| 40 | |
| 41 | /** Legacy alias for HIDDEN. */ |
| 42 | public const int NONE = 0; |
| 43 | |
| 44 | /** |
| 45 | * Checks if the given code is a valid special access status. |
| 46 | * |
| 47 | * @param int $status Status code to validate. |
| 48 | * @return bool True if valid special access code. |
| 49 | */ |
| 50 | public static function isValid(int $status): bool |
| 51 | { |
| 52 | return in_array($status, [ |
| 53 | self::HIDDEN, |
| 54 | self::AVAILABLE, |
| 55 | self::ARCHIVED, |
| 56 | self::DELETED, |
| 57 | ], true); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns human-readable label descriptor. |
| 62 | * |
| 63 | * @param int $status Status integer code. |
| 64 | * @return string Label descriptor. |
| 65 | */ |
| 66 | public static function getLabel(int $status): string |
| 67 | { |
| 68 | return match ($status) { |
| 69 | self::HIDDEN => 'Hidden', |
| 70 | self::AVAILABLE => 'Visible', |
| 71 | self::ARCHIVED => 'Archived', |
| 72 | self::DELETED => 'Deleted', |
| 73 | default => 'Unknown', |
| 74 | }; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns Bootstrap icon class. |
| 79 | * |
| 80 | * @param int $status Status integer code. |
| 81 | * @return string Bootstrap icon CSS class. |
| 82 | */ |
| 83 | public static function getIcon(int $status): string |
| 84 | { |
| 85 | return match ($status) { |
| 86 | self::HIDDEN => 'bi bi-eye-slash', |
| 87 | self::AVAILABLE => 'bi bi-check-circle', |
| 88 | self::ARCHIVED => 'bi bi-archive', |
| 89 | self::DELETED => 'bi bi-trash', |
| 90 | default => 'bi bi-question-circle', |
| 91 | }; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Returns Bootstrap badge theme color name. |
| 96 | * |
| 97 | * @param int $status Status integer code. |
| 98 | * @return string Bootstrap color class prefix. |
| 99 | */ |
| 100 | public static function getBadgeColor(int $status): string |
| 101 | { |
| 102 | return match ($status) { |
| 103 | self::HIDDEN => 'dark', |
| 104 | self::AVAILABLE => 'success', |
| 105 | self::ARCHIVED => 'warning', |
| 106 | self::DELETED => 'danger', |
| 107 | default => 'secondary', |
| 108 | }; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Returns all valid special access status codes. |
| 113 | * |
| 114 | * @return list<int> List of status codes. |
| 115 | */ |
| 116 | public static function all(): array |
| 117 | { |
| 118 | return [ |
| 119 | self::HIDDEN, |
| 120 | self::AVAILABLE, |
| 121 | self::ARCHIVED, |
| 122 | self::DELETED, |
| 123 | ]; |
| 124 | } |
| 125 | } |