Passed
Push — dev ( d91619...3d1f41 )
by Nico
14:25
created

Alliance::setDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Stu\Component\Alliance\AllianceEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Alliance\AllianceEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Stu\Component\Alliance\Exception\AllianceFounderNotSetException;
20
use Stu\Orm\Repository\AllianceRepository;
21
22
#[Table(name: 'stu_alliances')]
23
#[Entity(repositoryClass: AllianceRepository::class)]
24
class Alliance implements AllianceInterface
25
{
26
    #[Id]
27
    #[Column(type: 'integer')]
28
    #[GeneratedValue(strategy: 'IDENTITY')]
29
    private int $id;
30
31
    #[Column(type: 'string')]
32
    private string $name = '';
33
34
    #[Column(type: 'text')]
35
    private string $description = '';
36
37
    #[Column(type: 'string')]
38
    private string $homepage = '';
39
40
    #[Column(type: 'integer')]
41
    private int $date = 0;
42
43
    #[Column(type: 'integer', nullable: true)]
44
    private ?int $faction_id = null;
0 ignored issues
show
introduced by
The private property $faction_id is not used, and could be removed.
Loading history...
45
46
    #[Column(type: 'boolean')]
47
    private bool $accept_applications = false;
48
49
    #[Column(type: 'string', length: 32)]
50
    private string $avatar = '';
51
52
    #[Column(type: 'string', length: 7)]
53
    private string $rgb_code = '';
54
55
    #[ManyToOne(targetEntity: 'Faction')]
56
    #[JoinColumn(name: 'faction_id', referencedColumnName: 'id')]
57
    private ?FactionInterface $faction = null;
58
59
    /**
60
     * @var ArrayCollection<int, AllianceSettingsInterface>
61
     */
62
    #[OneToMany(targetEntity: 'AllianceSettings', mappedBy: 'alliance')]
63
    private Collection $settings;
64
65
66
    /**
67
     * @var ArrayCollection<int, UserInterface>
68
     */
69
    #[OneToMany(targetEntity: 'User', mappedBy: 'alliance')]
70
    private Collection $members;
71
72
    /**
73
     * @var ArrayCollection<int, AllianceJobInterface>
74
     */
75
    #[OneToMany(targetEntity: 'AllianceJob', mappedBy: 'alliance', indexBy: 'type')]
76
    private Collection $jobs;
77
78
79
    public function __construct()
80
    {
81
        $this->members = new ArrayCollection();
82
        $this->jobs = new ArrayCollection();
83
        $this->settings = new ArrayCollection();
84
    }
85
86 17
    #[Override]
87
    public function getId(): int
88
    {
89 17
        return $this->id;
90
    }
91
92 8
    #[Override]
93
    public function getName(): string
94
    {
95 8
        return $this->name;
96
    }
97
98
    #[Override]
99
    public function setName(string $name): AllianceInterface
100
    {
101
        $this->name = $name;
102
        return $this;
103
    }
104
105 2
    #[Override]
106
    public function getDescription(): string
107
    {
108 2
        return $this->description;
109
    }
110
111
    #[Override]
112
    public function setDescription(string $description): AllianceInterface
113
    {
114
        $this->description = $description;
115
        return $this;
116
    }
117
118 1
    #[Override]
119
    public function getHomepage(): string
120
    {
121 1
        return $this->homepage;
122
    }
123
124
    #[Override]
125
    public function setHomepage(string $homepage): AllianceInterface
126
    {
127
        $this->homepage = $homepage;
128
        return $this;
129
    }
130
131 1
    #[Override]
132
    public function getDate(): int
133
    {
134 1
        return $this->date;
135
    }
136
137
    #[Override]
138
    public function setDate(int $date): AllianceInterface
139
    {
140
        $this->date = $date;
141
        return $this;
142
    }
143
144 1
    #[Override]
145
    public function getFaction(): ?FactionInterface
146
    {
147 1
        return $this->faction;
148
    }
149
150
    #[Override]
151
    public function setFaction(?FactionInterface $faction): AllianceInterface
152
    {
153
        $this->faction = $faction;
154
        return $this;
155
    }
156
157 2
    #[Override]
158
    public function getAcceptApplications(): bool
159
    {
160 2
        return $this->accept_applications;
161
    }
162
163
    #[Override]
164
    public function setAcceptApplications(bool $acceptApplications): AllianceInterface
165
    {
166
        $this->accept_applications = $acceptApplications;
167
        return $this;
168
    }
169
170
    #[Override]
171
    public function hasAvatar(): bool
172
    {
173
        return strlen($this->getAvatar()) > 0;
174
    }
175
176 1
    #[Override]
177
    public function getAvatar(): string
178
    {
179 1
        return $this->avatar;
180
    }
181
182
    #[Override]
183
    public function setAvatar(string $avatar): AllianceInterface
184
    {
185
        $this->avatar = $avatar;
186
        return $this;
187
    }
188
189 1
    #[Override]
190
    public function getRgbCode(): string
191
    {
192 1
        return $this->rgb_code;
193
    }
194
195
    #[Override]
196
    public function setRgbCode(string $rgbCode): AllianceInterface
197
    {
198
        $this->rgb_code = $rgbCode;
199
        return $this;
200
    }
201
202
    /**
203
     * @throws AllianceFounderNotSetException
204
     */
205 9
    #[Override]
206
    public function getFounder(): AllianceJobInterface
207
    {
208 9
        $job = $this->jobs->get(AllianceEnum::ALLIANCE_JOBS_FOUNDER);
209 9
        if ($job === null) {
210
            // alliance without founder? this should not happen
211
            throw new AllianceFounderNotSetException();
212
        }
213 9
        return $job;
214
    }
215
216 9
    #[Override]
217
    public function getSuccessor(): ?AllianceJobInterface
218
    {
219 9
        return $this->jobs->get(AllianceEnum::ALLIANCE_JOBS_SUCCESSOR);
220
    }
221
222 2
    #[Override]
223
    public function getDiplomatic(): ?AllianceJobInterface
224
    {
225 2
        return $this->jobs->get(AllianceEnum::ALLIANCE_JOBS_DIPLOMATIC);
226
    }
227
228 2
    #[Override]
229
    public function getMembers(): Collection
230
    {
231 2
        return $this->members;
232
    }
233
234
    #[Override]
235
    public function isNpcAlliance(): bool
236
    {
237
        $founder = $this->jobs->get(AllianceEnum::ALLIANCE_JOBS_FOUNDER);
238
239
        if ($founder === null) {
240
            return false;
241
        }
242
243
        return $founder->getUser()->isNpc();
244
    }
245
246
    #[Override]
247
    public function getJobs(): Collection
248
    {
249
        return $this->jobs;
250
    }
251
252
    #[Override]
253
    public function __toString(): string
254
    {
255
        return $this->getName();
256
    }
257
258 1
    #[Override]
259
    public function hasTranslation(): bool
260
    {
261 1
        $text = $this->getDescription();
262 1
        return strpos($text, '[translate]') !== false && strpos($text, '[/translate]') !== false;
263
    }
264
265 3
    #[Override]
266
    public function getSettings(): Collection
267
    {
268 3
        return $this->settings;
269
    }
270
}
271