Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ProfileFieldPermission | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
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\Modules\Profiles\Domain\Model; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * Profile Field Permission Value Object. |
| 13 | * |
| 14 | * Encapsulates the field-level security permission for a specific field within a module. |
| 15 | * |
| 16 | * @package App\Modules\Profiles\Domain\Model |
| 17 | */ |
| 18 | final readonly class ProfileFieldPermission |
| 19 | { |
| 20 | /** |
| 21 | * ProfileFieldPermission constructor. |
| 22 | * |
| 23 | * @param int $profileId Profile identifier. |
| 24 | * @param string $moduleName Machine-readable module name. |
| 25 | * @param string $fieldKey Field key name. |
| 26 | * @param FieldPermissionType $permission Assigned permission level (edit, view, hide). |
| 27 | */ |
| 28 | public function __construct( |
| 29 | public int $profileId, |
| 30 | public string $moduleName, |
| 31 | public string $fieldKey, |
| 32 | public FieldPermissionType $permission = FieldPermissionType::EDIT, |
| 33 | ) { |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Converts value object to array. |
| 38 | * |
| 39 | * @return array<string, mixed> Associative representation. |
| 40 | */ |
| 41 | public function toArray(): array |
| 42 | { |
| 43 | return [ |
| 44 | 'profile_id' => $this->profileId, |
| 45 | 'module_name' => $this->moduleName, |
| 46 | 'field_key' => $this->fieldKey, |
| 47 | 'permission' => $this->permission->value, |
| 48 | ]; |
| 49 | } |
| 50 | } |