Passed
Push — master ( 32373f...f18c17 )
by Benjamin
05:50 queued 01:43
created

TeamVersion   A

Complexity

Total Complexity 42

Size/Duplication

Total Lines 353
Duplicated Lines 0 %

Test Coverage

Coverage 30.63%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 42
eloc 90
c 1
b 0
f 0
dl 0
loc 353
ccs 34
cts 111
cp 0.3063
rs 9.0399

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