Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ProfileModulePermission
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Profiles\Domain\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Profile Module Permission Value Object.
13 *
14 * Encapsulates CRUD permissions granted to a profile for a specific system module.
15 *
16 * @package App\Modules\Profiles\Domain\Model
17 */
18final readonly class ProfileModulePermission
19{
20    /**
21     * ProfileModulePermission constructor.
22     *
23     * @param int    $profileId   Profile identifier.
24     * @param string $moduleName  Machine-readable module name.
25     * @param bool   $canView     Permission to view / read module records.
26     * @param bool   $canCreate   Permission to create new module records.
27     * @param bool   $canEdit     Permission to update module records.
28     * @param bool   $canDelete   Permission to delete module records.
29     */
30    public function __construct(
31        public int    $profileId,
32        public string $moduleName,
33        public bool   $canView = true,
34        public bool   $canCreate = true,
35        public bool   $canEdit = true,
36        public bool   $canDelete = true,
37    ) {
38    }
39
40    /**
41     * Converts value object to array.
42     *
43     * @return array<string, mixed> Associative representation.
44     */
45    public function toArray(): array
46    {
47        return [
48            'profile_id'  => $this->profileId,
49            'module_name' => $this->moduleName,
50            'can_view'    => $this->canView,
51            'can_create'  => $this->canCreate,
52            'can_edit'    => $this->canEdit,
53            'can_delete'  => $this->canDelete,
54        ];
55    }
56}