Passed
Push — master ( 1c618d...c1c6b0 )
by Yannick
10:36 queued 02:52
created

XApiCmi5Item   B

Complexity

Total Complexity 44

Size/Duplication

Total Lines 328
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 115
c 1
b 0
f 0
dl 0
loc 328
rs 8.8798
wmc 44

41 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 3 1
A setLft() 0 5 1
A __construct() 0 3 1
A getIdentifier() 0 3 1
A getLft() 0 3 1
A getDescription() 0 3 1
A getType() 0 3 1
A getTitle() 0 3 1
A setEntitlementKey() 0 5 1
A getChildren() 0 3 1
A setLaunchMethod() 0 5 1
A getTool() 0 3 1
A getñlvl() 0 3 1
A setMasteryScore() 0 5 1
A getRoot() 0 3 1
A setMoveOn() 0 5 1
A getId() 0 3 1
A setParent() 0 5 1
A setUrl() 0 5 1
A setRgt() 0 5 1
A setActivityType() 0 5 1
A getStatus() 0 3 1
A setRoot() 0 5 1
A getMasteryScore() 0 3 1
A setDescription() 0 5 1
A removeChild() 0 10 3
A getLaunchMethod() 0 3 1
A getParent() 0 3 1
A setTool() 0 5 1
A setType() 0 5 1
A getEntitlementKey() 0 3 1
A getLaunchParameters() 0 3 1
A setIdentifier() 0 5 1
A setñlvl() 0 5 1
A getActivityType() 0 3 1
A setLaunchParameters() 0 5 1
A addChild() 0 8 2
A getMoveOn() 0 3 1
A setStatus() 0 5 1
A setTitle() 0 5 1
A getRgt() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like XApiCmi5Item 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 XApiCmi5Item, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\Entity;
8
9
use Chamilo\CoreBundle\Repository\XApiCmi5ItemRepository;
10
use Doctrine\Common\Collections\ArrayCollection;
11
use Doctrine\Common\Collections\Collection;
12
use Doctrine\ORM\Mapping as ORM;
13
use Gedmo\Mapping\Annotation as Gedmo;
14
15
#[Gedmo\Tree(type: 'nested')]
16
#[ORM\Entity(repositoryClass: XApiCmi5ItemRepository::class)]
17
class XApiCmi5Item
18
{
19
    #[ORM\Id]
20
    #[ORM\GeneratedValue]
21
    #[ORM\Column]
22
    private ?int $id = null;
23
24
    #[ORM\Column(length: 255)]
25
    private ?string $identifier = null;
26
27
    #[ORM\Column(length: 255)]
28
    private ?string $type = null;
29
30
    #[ORM\Column]
31
    private array $title = [];
32
33
    #[ORM\Column]
34
    private array $description = [];
35
36
    #[ORM\Column(length: 255, nullable: true)]
37
    private ?string $url = null;
38
39
    #[ORM\Column(length: 255, nullable: true)]
40
    private ?string $activityType = null;
41
42
    #[ORM\Column(length: 255, nullable: true)]
43
    private ?string $launchMethod = null;
44
45
    #[ORM\Column(length: 255, nullable: true)]
46
    private ?string $moveOn = null;
47
48
    #[ORM\Column(nullable: true)]
49
    private ?float $masteryScore = null;
50
51
    #[ORM\Column(length: 255, nullable: true)]
52
    private ?string $launchParameters = null;
53
54
    #[ORM\Column(length: 255, nullable: true)]
55
    private ?string $entitlementKey = null;
56
57
    #[ORM\Column(length: 255, nullable: true)]
58
    private ?string $status = null;
59
60
    #[Gedmo\TreeLeft]
61
    #[ORM\Column]
62
    private ?int $lft = null;
63
64
    #[Gedmo\TreeLevel]
65
    #[ORM\Column]
66
    private ?int $lvl = null;
67
68
    #[Gedmo\TreeRight]
69
    #[ORM\Column]
70
    private ?int $rgt = null;
71
72
    #[Gedmo\TreeRoot]
73
    #[ORM\ManyToOne(targetEntity: self::class)]
74
    private ?self $root = null;
75
76
    #[Gedmo\TreeParent]
77
    #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
78
    private ?self $parent = null;
79
80
    /**
81
     * @var Collection<int, self>
82
     */
83
    #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
84
    private Collection $children;
85
86
    #[ORM\ManyToOne(inversedBy: 'items')]
87
    private ?XApiToolLaunch $tool = null;
88
89
    public function __construct()
90
    {
91
        $this->children = new ArrayCollection();
92
    }
93
94
    public function getId(): ?int
95
    {
96
        return $this->id;
97
    }
98
99
    public function getIdentifier(): ?string
100
    {
101
        return $this->identifier;
102
    }
103
104
    public function setIdentifier(string $identifier): static
105
    {
106
        $this->identifier = $identifier;
107
108
        return $this;
109
    }
110
111
    public function getType(): ?string
112
    {
113
        return $this->type;
114
    }
115
116
    public function setType(string $type): static
117
    {
118
        $this->type = $type;
119
120
        return $this;
121
    }
122
123
    public function getTitle(): array
124
    {
125
        return $this->title;
126
    }
127
128
    public function setTitle(array $title): static
129
    {
130
        $this->title = $title;
131
132
        return $this;
133
    }
134
135
    public function getDescription(): array
136
    {
137
        return $this->description;
138
    }
139
140
    public function setDescription(array $description): static
141
    {
142
        $this->description = $description;
143
144
        return $this;
145
    }
146
147
    public function getUrl(): ?string
148
    {
149
        return $this->url;
150
    }
151
152
    public function setUrl(?string $url): static
153
    {
154
        $this->url = $url;
155
156
        return $this;
157
    }
158
159
    public function getActivityType(): ?string
160
    {
161
        return $this->activityType;
162
    }
163
164
    public function setActivityType(?string $activityType): static
165
    {
166
        $this->activityType = $activityType;
167
168
        return $this;
169
    }
170
171
    public function getLaunchMethod(): ?string
172
    {
173
        return $this->launchMethod;
174
    }
175
176
    public function setLaunchMethod(?string $launchMethod): static
177
    {
178
        $this->launchMethod = $launchMethod;
179
180
        return $this;
181
    }
182
183
    public function getMoveOn(): ?string
184
    {
185
        return $this->moveOn;
186
    }
187
188
    public function setMoveOn(?string $moveOn): static
189
    {
190
        $this->moveOn = $moveOn;
191
192
        return $this;
193
    }
194
195
    public function getMasteryScore(): ?float
196
    {
197
        return $this->masteryScore;
198
    }
199
200
    public function setMasteryScore(?float $masteryScore): static
201
    {
202
        $this->masteryScore = $masteryScore;
203
204
        return $this;
205
    }
206
207
    public function getLaunchParameters(): ?string
208
    {
209
        return $this->launchParameters;
210
    }
211
212
    public function setLaunchParameters(?string $launchParameters): static
213
    {
214
        $this->launchParameters = $launchParameters;
215
216
        return $this;
217
    }
218
219
    public function getEntitlementKey(): ?string
220
    {
221
        return $this->entitlementKey;
222
    }
223
224
    public function setEntitlementKey(?string $entitlementKey): static
225
    {
226
        $this->entitlementKey = $entitlementKey;
227
228
        return $this;
229
    }
230
231
    public function getStatus(): ?string
232
    {
233
        return $this->status;
234
    }
235
236
    public function setStatus(?string $status): static
237
    {
238
        $this->status = $status;
239
240
        return $this;
241
    }
242
243
    public function getLft(): ?int
244
    {
245
        return $this->lft;
246
    }
247
248
    public function setLft(int $lft): static
249
    {
250
        $this->lft = $lft;
251
252
        return $this;
253
    }
254
255
    public function getñlvl(): ?int
256
    {
257
        return $this->lvl;
258
    }
259
260
    public function setñlvl(int $lvl): static
261
    {
262
        $this->lvl = $lvl;
263
264
        return $this;
265
    }
266
267
    public function getRgt(): ?int
268
    {
269
        return $this->rgt;
270
    }
271
272
    public function setRgt(int $rgt): static
273
    {
274
        $this->rgt = $rgt;
275
276
        return $this;
277
    }
278
279
    public function getRoot(): ?self
280
    {
281
        return $this->root;
282
    }
283
284
    public function setRoot(?self $root): static
285
    {
286
        $this->root = $root;
287
288
        return $this;
289
    }
290
291
    public function getParent(): ?self
292
    {
293
        return $this->parent;
294
    }
295
296
    public function setParent(?self $parent): static
297
    {
298
        $this->parent = $parent;
299
300
        return $this;
301
    }
302
303
    /**
304
     * @return Collection<int, self>
305
     */
306
    public function getChildren(): Collection
307
    {
308
        return $this->children;
309
    }
310
311
    public function addChild(self $child): static
312
    {
313
        if (!$this->children->contains($child)) {
314
            $this->children->add($child);
315
            $child->setParent($this);
316
        }
317
318
        return $this;
319
    }
320
321
    public function removeChild(self $child): static
322
    {
323
        if ($this->children->removeElement($child)) {
324
            // set the owning side to null (unless already changed)
325
            if ($child->getParent() === $this) {
326
                $child->setParent(null);
327
            }
328
        }
329
330
        return $this;
331
    }
332
333
    public function getTool(): ?XApiToolLaunch
334
    {
335
        return $this->tool;
336
    }
337
338
    public function setTool(?XApiToolLaunch $tool): static
339
    {
340
        $this->tool = $tool;
341
342
        return $this;
343
    }
344
}
345