Role   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 86
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
A getId() 0 3 1
A setDescription() 0 5 1
A getUserGroups() 0 3 1
A __construct() 0 21 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Entity/Role.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Entity;
10
11
use App\Entity\Interfaces\EntityInterface;
12
use App\Entity\Traits\Blameable;
13
use App\Entity\Traits\Timestampable;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Doctrine\DBAL\Types\Types;
17
use Doctrine\ORM\Mapping as ORM;
18
use Symfony\Component\Serializer\Annotation\Groups;
19
20
/**
21
 * Class Role
22
 *
23
 * @package App\Entity
24
 * @author TLe, Tarmo Leppänen <[email protected]>
25
 */
26
#[ORM\Entity]
27
#[ORM\Table(
28
    name: 'role',
29
)]
30
#[ORM\UniqueConstraint(
31
    name: 'uq_role',
32
    columns: [
33
        'role',
34
    ],
35
)]
36
#[ORM\ChangeTrackingPolicy('DEFERRED_EXPLICIT')]
37
class Role implements EntityInterface
38
{
39
    use Blameable;
40
    use Timestampable;
41
42
    #[ORM\Column(
43
        name: 'description',
44
        type: Types::TEXT,
45
    )]
46
    #[Groups([
47
        'Role',
48
        'Role.description',
49
    ])]
50
    private string $description = '';
51
52
    /**
53
     * User groups that belongs to this role.
54
     *
55
     * @var Collection<int, UserGroup>|ArrayCollection<int, UserGroup>
56
     */
57
    #[ORM\OneToMany(
58
        mappedBy: 'role',
59
        targetEntity: UserGroup::class,
60
    )]
61
    #[Groups([
62
        'Role.userGroups',
63
    ])]
64
    private Collection | ArrayCollection $userGroups;
65
66 63
    public function __construct(
67
        #[ORM\Id]
68
        #[ORM\Column(
69
            name: 'role',
70
            type: Types::STRING,
71
            unique: true,
72
            nullable: false,
73
        )]
74
        #[Groups([
75
            'Role',
76
            'Role.id',
77
78
            'UserGroup.role',
79
80
            User::SET_USER_BASIC,
81
            UserGroup::SET_USER_PROFILE_GROUPS,
82
            UserGroup::SET_USER_GROUP_BASIC,
83
        ])]
84
        private string $id
85
    ) {
86 63
        $this->userGroups = new ArrayCollection();
87
    }
88
89 226
    public function getId(): string
90
    {
91 226
        return $this->id;
92
    }
93
94 10
    public function getDescription(): string
95
    {
96 10
        return $this->description;
97
    }
98
99 19
    public function setDescription(string $description): self
100
    {
101 19
        $this->description = $description;
102
103 19
        return $this;
104
    }
105
106
    /**
107
     * @return Collection<int, UserGroup>|ArrayCollection<int, UserGroup>
108
     */
109 3
    public function getUserGroups(): Collection | ArrayCollection
110
    {
111 3
        return $this->userGroups;
112
    }
113
}
114