Completed
Branch v1.x-dev (6fcd50)
by Benjamin
04:47
created

TeamVersion   B

Complexity

Total Complexity 43

Size/Duplication

Total Lines 361
Duplicated Lines 0 %

Test Coverage

Coverage 29.82%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 43
eloc 93
c 1
b 0
f 0
dl 0
loc 361
ccs 34
cts 114
cp 0.2982
rs 8.96

40 Methods

Rating   Name   Duplication   Size   Complexity  
A getTreasure() 0 3 1
A getGameDraw() 0 3 1
A getInjuryGive() 0 3 1
A setTdGive() 0 5 1
A getTdTake() 0 3 1
A getPoints() 0 3 1
A setPoints() 0 5 1
A getPlayerVersions() 0 3 1
A getRerolls() 0 3 1
A setTeam() 0 5 1
A getGameLoss() 0 3 1
A getTr() 0 3 1
A setAssistants() 0 5 1
A setGameWin() 0 5 1
A setUpdatedAtValue() 0 4 1
A setRerolls() 0 5 1
A addPlayerVersion() 0 8 2
A getId() 0 3 1
A setTreasure() 0 5 1
A setPopularity() 0 5 1
A getCheerleaders() 0 3 1
A setInjuryTake() 0 5 1
A __construct() 0 8 1
A setTdTake() 0 5 1
A getAssistants() 0 3 1
A setInjuryGive() 0 5 1
A getTdGive() 0 3 1
A getTeam() 0 3 1
A setGameDraw() 0 5 1
A setGameLoss() 0 5 1
A setTr() 0 5 1
A setCheerleaders() 0 5 1
A getPopularity() 0 3 1
A getAvailablePlayerVersions() 0 6 1
A getNotDeadPlayerVersions() 0 6 1
A removePlayerVersion() 0 11 3
A setApothecary() 0 5 1
A getGameWin() 0 3 1
A getInjuryTake() 0 3 1
A getApothecary() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like TeamVersion often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TeamVersion, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Obblm\Core\Entity;
4
5
use Obblm\Core\Entity\Traits\TimeStampableTrait;
6
use Obblm\Core\Repository\TeamVersionRepository;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\Common\Collections\Criteria;
10
use Doctrine\ORM\Mapping as ORM;
11
12
/**
13
 * @ORM\Entity(repositoryClass=TeamVersionRepository::class)
14
 * @ORM\Table(name="obblm_team_version")
15
 * @ORM\HasLifecycleCallbacks
16
 */
17
class TeamVersion
18
{
19
    use TimeStampableTrait;
20
21
    /**
22
     * @ORM\Id
23
     * @ORM\GeneratedValue
24
     * @ORM\Column(type="integer")
25
     */
26
    private $id;
27
28
    /**
29
     * @ORM\ManyToOne(targetEntity=Team::class, fetch="EAGER", inversedBy="versions", cascade="persist")
30
     * @ORM\JoinColumn(nullable=false)
31
     */
32
    private $team;
33
34
    /**
35
     * @ORM\OneToMany(targetEntity=PlayerVersion::class, mappedBy="teamVersion", orphanRemoval=true, cascade={"persist", "remove"})
36
     */
37
    private $playerVersions;
38
39
    /**
40
     * @ORM\Column(type="integer")
41
     */
42
    private $rerolls;
43
44
    /**
45
     * @ORM\Column(type="integer")
46
     */
47
    private $cheerleaders;
48
49
    /**
50
     * @ORM\Column(type="integer")
51
     */
52
    private $assistants;
53
54
    /**
55
     * @ORM\Column(type="integer")
56
     */
57
    private $popularity;
58
59
    /**
60
     * @ORM\Column(type="boolean")
61
     */
62
    private $apothecary;
63
64
    /**
65
     * @ORM\Column(type="integer")
66
     */
67
    private $points = 0;
68
69
    /**
70
     * @ORM\Column(type="integer")
71
     */
72
    private $tdGive = 0;
73
74
    /**
75
     * @ORM\Column(type="integer")
76
     */
77
    private $tdTake = 0;
78
79
    /**
80
     * @ORM\Column(type="integer")
81
     */
82
    private $injuryGive = 0;
83
84
    /**
85
     * @ORM\Column(type="integer")
86
     */
87
    private $injuryTake = 0;
88
89
    /**
90
     * @ORM\Column(type="integer")
91
     */
92
    private $gameWin = 0;
93
94
    /**
95
     * @ORM\Column(type="integer")
96
     */
97
    private $gameDraw = 0;
98
99
    /**
100
     * @ORM\Column(type="integer")
101
     */
102
    private $gameLoss = 0;
103
104
    /**
105
     * @ORM\Column(type="integer")
106
     */
107
    private $treasure = 0;
108
109
    /**
110
     * @ORM\Column(type="integer")
111
     */
112
    private $tr = 0;
113
114 2
    public function __construct()
115
    {
116 2
        $this->playerVersions = new ArrayCollection();
117 2
        $this->apothecary = false;
118 2
        $this->rerolls = 0;
119 2
        $this->cheerleaders = 0;
120 2
        $this->assistants = 0;
121 2
        $this->popularity = 0;
122 2
    }
123
124
    public function getId(): ?int
125
    {
126
        return $this->id;
127
    }
128
129 2
    public function getTeam(): ?Team
130
    {
131 2
        return $this->team;
132
    }
133
134 1
    public function setTeam(?Team $team): self
135
    {
136 1
        $this->team = $team;
137
138 1
        return $this;
139
    }
140
141
    /**
142
     * @return Collection|PlayerVersion[]
143
     */
144
    public function getPlayerVersions(): Collection
145
    {
146
        return $this->playerVersions;
147
    }
148
149
    /**
150
     * @return Collection|PlayerVersion[]
151
     */
152
    public function getNotDeadPlayerVersions(): Collection
153
    {
154
        $criteria = Criteria::create()
155
            ->andWhere(Criteria::expr()->eq('dead', false))
156
        ;
157
        return $this->playerVersions->matching($criteria);
158
    }
159
160
    /**
161
     * @return Collection|PlayerVersion[]
162
     */
163
    public function getAvailablePlayerVersions(): Collection
164
    {
165
        $criteria = Criteria::create()
166
            ->andWhere(Criteria::expr()->eq('dead', false))
167
        ;
168
        return $this->playerVersions->matching($criteria);
169
    }
170
171 1
    public function addPlayerVersion(PlayerVersion $playerVersion): self
172
    {
173 1
        if (!$this->playerVersions->contains($playerVersion)) {
174 1
            $this->playerVersions[] = $playerVersion;
175 1
            $playerVersion->setTeamVersion($this);
176
        }
177
178 1
        return $this;
179
    }
180
181
    public function removePlayerVersion(PlayerVersion $playerVersion): self
182
    {
183
        if ($this->playerVersions->contains($playerVersion)) {
184
            $this->playerVersions->removeElement($playerVersion);
185
            // set the owning side to null (unless already changed)
186
            if ($playerVersion->getTeamVersion() === $this) {
187
                $playerVersion->setTeamVersion(null);
188
            }
189
        }
190
191
        return $this;
192
    }
193
194 1
    public function getRerolls(): ?int
195
    {
196 1
        return $this->rerolls;
197
    }
198
199 1
    public function setRerolls(int $rerolls): self
200
    {
201 1
        $this->rerolls = $rerolls;
202
203 1
        return $this;
204
    }
205
206 1
    public function getCheerleaders(): ?int
207
    {
208 1
        return $this->cheerleaders;
209
    }
210
211
    public function setCheerleaders(int $cheerleaders): self
212
    {
213
        $this->cheerleaders = $cheerleaders;
214
215
        return $this;
216
    }
217
218 1
    public function getAssistants(): ?int
219
    {
220 1
        return $this->assistants;
221
    }
222
223
    public function setAssistants(int $assistants): self
224
    {
225
        $this->assistants = $assistants;
226
227
        return $this;
228
    }
229
230 1
    public function getPopularity(): ?int
231
    {
232 1
        return $this->popularity;
233
    }
234
235
    public function setPopularity(int $popularity): self
236
    {
237
        $this->popularity = $popularity;
238
239
        return $this;
240
    }
241
242 1
    public function getApothecary(): ?bool
243
    {
244 1
        return $this->apothecary;
245
    }
246
247 1
    public function setApothecary(bool $apothecary): self
248
    {
249 1
        $this->apothecary = $apothecary;
250
251 1
        return $this;
252
    }
253
254
    public function getTdGive(): ?int
255
    {
256
        return $this->tdGive;
257
    }
258
259
    public function setTdGive(int $tdGive): self
260
    {
261
        $this->tdGive = $tdGive;
262
263
        return $this;
264
    }
265
266
    public function getTdTake(): ?int
267
    {
268
        return $this->tdTake;
269
    }
270
271
    public function setTdTake(int $tdTake): self
272
    {
273
        $this->tdTake = $tdTake;
274
275
        return $this;
276
    }
277
278
    public function getInjuryGive(): ?int
279
    {
280
        return $this->injuryGive;
281
    }
282
283
    public function setInjuryGive(int $injuryGive): self
284
    {
285
        $this->injuryGive = $injuryGive;
286
287
        return $this;
288
    }
289
290
    public function getInjuryTake(): ?int
291
    {
292
        return $this->injuryTake;
293
    }
294
295
    public function setInjuryTake(int $injuryTake): self
296
    {
297
        $this->injuryTake = $injuryTake;
298
299
        return $this;
300
    }
301
302
    public function getGameWin(): ?int
303
    {
304
        return $this->gameWin;
305
    }
306
307
    public function setGameWin(int $gameWin): self
308
    {
309
        $this->gameWin = $gameWin;
310
311
        return $this;
312
    }
313
314
    public function getGameDraw(): ?int
315
    {
316
        return $this->gameDraw;
317
    }
318
319
    public function setGameDraw(int $gameDraw): self
320
    {
321
        $this->gameDraw = $gameDraw;
322
323
        return $this;
324
    }
325
326
    public function getGameLoss(): ?int
327
    {
328
        return $this->gameLoss;
329
    }
330
331
    public function setGameLoss(int $gameLoss): self
332
    {
333
        $this->gameLoss = $gameLoss;
334
335
        return $this;
336
    }
337
338
    public function getTreasure(): ?int
339
    {
340
        return $this->treasure;
341
    }
342
343
    public function setTreasure(int $treasure): self
344
    {
345
        $this->treasure = $treasure;
346
347
        return $this;
348
    }
349
350
    public function getTr(): ?int
351
    {
352
        return $this->tr;
353
    }
354
355
    public function setTr(int $tr): self
356
    {
357
        $this->tr = $tr;
358
359
        return $this;
360
    }
361
362
    public function getPoints(): ?int
363
    {
364
        return $this->points;
365
    }
366
367
    public function setPoints(int $points): self
368
    {
369
        $this->points = $points;
370
371
        return $this;
372
    }
373
374
    public function setUpdatedAtValue()
375
    {
376
        $this->updatedAt = new \DateTime();
377
        $this->getTeam()->setUpdatedAt(new \DateTime());
378
    }
379
}
380