Passed
Push — master ( 920d42...f78319 )
by Nico
10:24 queued 05:13
created

AllianceJob   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Test Coverage

Coverage 57.69%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 55
c 1
b 0
f 0
dl 0
loc 150
ccs 30
cts 52
cp 0.5769
rs 10
wmc 23

19 Methods

Rating   Name   Duplication   Size   Complexity  
A setIsFounderPermission() 0 4 1
A getMemberAssignments() 0 3 1
A getSort() 0 3 1
A getUser() 0 4 2
A hasUser() 0 8 3
A getTitle() 0 3 1
A setTitle() 0 4 1
A setAlliance() 0 4 1
A setIsDiplomaticPermission() 0 4 1
A hasDiplomaticPermission() 0 3 1
A getId() 0 3 1
A getUsers() 0 5 1
A setIsSuccessorPermission() 0 4 1
A hasSuccessorPermission() 0 3 1
A setSort() 0 4 1
A __construct() 0 3 1
A getAlliance() 0 3 1
A hasFounderPermission() 0 3 1
A getUserId() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping\Column;
10
use Doctrine\ORM\Mapping\Entity;
11
use Doctrine\ORM\Mapping\GeneratedValue;
12
use Doctrine\ORM\Mapping\Id;
13
use Doctrine\ORM\Mapping\JoinColumn;
14
use Doctrine\ORM\Mapping\ManyToOne;
15
use Doctrine\ORM\Mapping\OneToMany;
16
use Doctrine\ORM\Mapping\Table;
17
use Stu\Orm\Attribute\TruncateOnGameReset;
18
use Stu\Orm\Repository\AllianceJobRepository;
19
20
#[Table(name: 'stu_alliances_jobs')]
21
#[Entity(repositoryClass: AllianceJobRepository::class)]
22
#[TruncateOnGameReset]
23
class AllianceJob
24
{
25
    #[Id]
26
    #[Column(type: 'integer')]
27
    #[GeneratedValue(strategy: 'IDENTITY')]
28
    private int $id;
29
30
    #[ManyToOne(targetEntity: Alliance::class, inversedBy: 'jobs')]
31
    #[JoinColumn(name: 'alliance_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')]
32
    private Alliance $alliance;
33
34
    #[Column(type: 'string', nullable: true)]
35
    private ?string $title = null;
36
37
    #[Column(type: 'integer', nullable: true)]
38
    private ?int $sort = null;
39
40
    #[Column(type: 'boolean', options: ['default' => false])]
41
    private bool $is_founder_permission = false;
42
43
    #[Column(type: 'boolean', options: ['default' => false])]
44
    private bool $is_successor_permission = false;
45
46
    #[Column(type: 'boolean', options: ['default' => false])]
47
    private bool $is_diplomatic_permission = false;
48
49
    /**
50
     * @var ArrayCollection<int, AllianceMemberJob>
51
     */
52
    #[OneToMany(targetEntity: AllianceMemberJob::class, mappedBy: 'job', cascade: ['remove'])]
53
    private Collection $memberAssignments;
54
55
    public function __construct()
56
    {
57
        $this->memberAssignments = new ArrayCollection();
58
    }
59
60 1
    public function getId(): int
61
    {
62 1
        return $this->id;
63
    }
64
65 9
    public function getAlliance(): Alliance
66
    {
67 9
        return $this->alliance;
68
    }
69
70
    public function setAlliance(Alliance $alliance): AllianceJob
71
    {
72
        $this->alliance = $alliance;
73
        return $this;
74
    }
75
76 2
    public function getTitle(): ?string
77
    {
78 2
        return $this->title;
79
    }
80
81
    public function setTitle(string $title): AllianceJob
82
    {
83
        $this->title = $title;
84
        return $this;
85
    }
86
87 3
    public function getSort(): ?int
88
    {
89 3
        return $this->sort;
90
    }
91
92
    public function setSort(?int $sort): AllianceJob
93
    {
94
        $this->sort = $sort;
95
        return $this;
96
    }
97
98 9
    public function hasFounderPermission(): bool
99
    {
100 9
        return $this->is_founder_permission;
101
    }
102
103
    public function setIsFounderPermission(bool $isFounderPermission): AllianceJob
104
    {
105
        $this->is_founder_permission = $isFounderPermission;
106
        return $this;
107
    }
108
109 1
    public function hasSuccessorPermission(): bool
110
    {
111 1
        return $this->is_successor_permission;
112
    }
113
114
    public function setIsSuccessorPermission(bool $isSuccessorPermission): AllianceJob
115
    {
116
        $this->is_successor_permission = $isSuccessorPermission;
117
        return $this;
118
    }
119
120 3
    public function hasDiplomaticPermission(): bool
121
    {
122 3
        return $this->is_diplomatic_permission;
123
    }
124
125
    public function setIsDiplomaticPermission(bool $isDiplomaticPermission): AllianceJob
126
    {
127
        $this->is_diplomatic_permission = $isDiplomaticPermission;
128
        return $this;
129
    }
130
131
    /**
132
     * @return Collection<int, AllianceMemberJob>
133
     */
134
    public function getMemberAssignments(): Collection
135
    {
136
        return $this->memberAssignments;
137
    }
138
139
    /**
140
     * @return array<User>
141
     */
142 1
    public function getUsers(): array
143
    {
144 1
        return array_map(
145 1
            fn(AllianceMemberJob $assignment) => $assignment->getUser(),
146 1
            $this->memberAssignments->toArray()
147 1
        );
148
    }
149
150 1
    public function hasUser(User $user): bool
151
    {
152 1
        foreach ($this->memberAssignments as $assignment) {
153 1
            if ($assignment->getUser()->getId() === $user->getId()) {
154 1
                return true;
155
            }
156
        }
157 1
        return false;
158
    }
159
160 1
    public function getUser(): ?User
161
    {
162 1
        $first = $this->memberAssignments->first();
163 1
        return $first !== false ? $first->getUser() : null;
164
    }
165
166 1
    public function getUserId(): ?int
167
    {
168 1
        $user = $this->getUser();
169 1
        return $user !== null ? $user->getId() : null;
170
    }
171
}
172