Album   B
last analyzed

Complexity

Total Complexity 40

Size/Duplication

Total Lines 482
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 98%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 40
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 482
ccs 98
cts 100
cp 0.98
rs 8.2609

40 Methods

Rating   Name   Duplication   Size   Complexity  
A setAlbumId() 0 6 1
A getAlbumId() 0 4 1
A setTitle() 0 6 1
A getTitle() 0 4 1
A setDescription() 0 6 1
A getDescription() 0 4 1
A setInsertedIntoGallery() 0 6 1
A getInsertedIntoGallery() 0 4 1
A setCover() 0 6 1
A getCover() 0 4 1
A setCoverWidth() 0 6 1
A getCoverWidth() 0 4 1
A setCoverHeight() 0 6 1
A getCoverHeight() 0 4 1
A setAccountUsername() 0 6 1
A getAccountUsername() 0 4 1
A setAccountId() 0 6 1
A getAccountId() 0 4 1
A setPrivacy() 0 6 1
A getPrivacy() 0 4 1
A setLayout() 0 6 1
A getLayout() 0 4 1
A setViews() 0 6 1
A getViews() 0 4 1
A setLink() 0 6 1
A getLink() 0 4 1
A setFavorite() 0 6 1
A isFavorite() 0 4 1
A setNsfw() 0 6 1
A isNsfw() 0 4 1
A setSection() 0 6 1
A getSection() 0 4 1
A setOrder() 0 6 1
A getOrder() 0 4 1
A setDeleteHash() 0 6 1
A getDeleteHash() 0 4 1
A setImagesCount() 0 6 1
A getImagesCount() 0 4 1
A setImages() 0 6 1
A getImages() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like Album 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

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 Album, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Mechpave\ImgurClient\Entity;
4
5
/**
6
 * Class Album
7
 * @package Mechpave\ImgurClient\Entity
8
 */
9
class Album implements AlbumInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $albumId;
15
16
    /**
17
     * @var string
18
     */
19
    protected $title;
20
21
    /**
22
     * @var string
23
     */
24
    protected $description;
25
26
    /**
27
     * @var \DateTime
28
     */
29
    protected $insertedIntoGallery;
30
31
    /**
32
     * @var string
33
     */
34
    protected $cover;
35
36
    /**
37
     * @var int
38
     */
39
    protected $coverWidth;
40
41
    /**
42
     * @var int
43
     */
44
    protected $coverHeight;
45
46
    /**
47
     * @var string
48
     */
49
    protected $accountUsername;
50
51
    /**
52
     * @var string
53
     */
54
    protected $accountId;
55
56
    /**
57
     * @var string
58
     */
59
    protected $privacy;
60
61
    /**
62
     * @var string
63
     */
64
    protected $layout;
65
66
    /**
67
     * @var int
68
     */
69
    protected $views;
70
71
    /**
72
     * @var string
73
     */
74
    protected $link;
75
76
    /**
77
     * @var bool
78
     */
79
    protected $favorite;
80
81
    /**
82
     * @var bool
83
     */
84
    protected $nsfw;
85
86
    /**
87
     * @var string
88
     */
89
    protected $section;
90
91
    /**
92
     * @var int
93
     */
94
    protected $order;
95
96
    /**
97
     * @var string
98
     */
99
    protected $deleteHash;
100
101
    /**
102
     * @var int
103
     */
104
    protected $imagesCount;
105
106
    /**
107
     * @var ImageInterface[]
108
     */
109
    protected $images;
110
111
    /**
112
     * @param string $id
113
     * @return AlbumInterface
114
     */
115 1
    public function setAlbumId($id)
116
    {
117 1
        $this->albumId = $id;
118
119 1
        return $this;
120
    }
121
122
    /**
123
     * @return string
124
     */
125 1
    public function getAlbumId()
126
    {
127 1
        return $this->albumId;
128
    }
129
130
    /**
131
     * @param string $title
132
     * @return AlbumInterface
133
     */
134 1
    public function setTitle($title)
135
    {
136 1
        $this->title = $title;
137
138 1
        return $this;
139
    }
140
141
    /**
142
     * @return string
143
     */
144 1
    public function getTitle()
145
    {
146 1
        return $this->title;
147
    }
148
149
    /**
150
     * @param string $description
151
     * @return AlbumInterface
152
     */
153 1
    public function setDescription($description)
154
    {
155 1
        $this->description = $description;
156
157 1
        return $this;
158
    }
159
160
    /**
161
     * @return string
162
     */
163 1
    public function getDescription()
164
    {
165 1
        return $this->description;
166
    }
167
168
    /**
169
     * @param \DateTime $dateTime
170
     * @return AlbumInterface
171
     */
172 1
    public function setInsertedIntoGallery($dateTime)
173
    {
174 1
        $this->insertedIntoGallery = $dateTime;
175
176 1
        return $this;
177
    }
178
179
    /**
180
     * @return \DateTime
181
     */
182 1
    public function getInsertedIntoGallery()
183
    {
184 1
        return $this->insertedIntoGallery;
185
    }
186
187
    /**
188
     * @param string $cover
189
     * @return AlbumInterface
190
     */
191 1
    public function setCover($cover)
192
    {
193 1
        $this->cover = $cover;
194
195 1
        return $this;
196
    }
197
198
    /**
199
     * @return string
200
     */
201 1
    public function getCover()
202
    {
203 1
        return $this->cover;
204
    }
205
206
    /**
207
     * @param int $coverWidth
208
     * @return AlbumInterface
209
     */
210 1
    public function setCoverWidth($coverWidth)
211
    {
212 1
        $this->coverWidth = $coverWidth;
213
214 1
        return $this;
215
    }
216
217
    /**
218
     * @return int
219
     */
220 1
    public function getCoverWidth()
221
    {
222 1
        return $this->coverWidth;
223
    }
224
225
    /**
226
     * @param int $coverHeight
227
     * @return AlbumInterface
228
     */
229 1
    public function setCoverHeight($coverHeight)
230
    {
231 1
        $this->coverHeight = $coverHeight;
232
233 1
        return $this;
234
    }
235
236
    /**
237
     * @return int
238
     */
239 1
    public function getCoverHeight()
240
    {
241 1
        return $this->coverHeight;
242
    }
243
244
    /**
245
     * @param string $accountUsername
246
     * @return AlbumInterface
247
     */
248 1
    public function setAccountUsername($accountUsername)
249
    {
250 1
        $this->accountUsername = $accountUsername;
251
252 1
        return $this;
253
    }
254
255
    /**
256
     * @return string
257
     */
258 1
    public function getAccountUsername()
259
    {
260 1
        return $this->accountUsername;
261
    }
262
263
    /**
264
     * @param integer $accountId
265
     * @return AlbumInterface
266
     */
267 1
    public function setAccountId($accountId)
268
    {
269 1
        $this->accountId = $accountId;
0 ignored issues
show
Documentation Bug introduced by
The property $accountId was declared of type string, but $accountId is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
270
271 1
        return $this;
272
    }
273
274
    /**
275
     * @return string
276
     */
277 1
    public function getAccountId()
278
    {
279 1
        return $this->accountId;
280
    }
281
282
    /**
283
     * @param string $privacy
284
     * @return AlbumInterface
285
     */
286 1
    public function setPrivacy($privacy)
287
    {
288 1
        $this->privacy = $privacy;
289
290 1
        return $this;
291
    }
292
293
    /**
294
     * @return string
295
     */
296 1
    public function getPrivacy()
297
    {
298 1
        return $this->privacy;
299
    }
300
301
    /**
302
     * @param string $layout
303
     * @return AlbumInterface
304
     */
305 1
    public function setLayout($layout)
306
    {
307 1
        $this->layout = $layout;
308
309 1
        return $this;
310
    }
311
312
    /**
313
     * @return string
314
     */
315 1
    public function getLayout()
316
    {
317 1
        return $this->layout;
318
    }
319
320
    /**
321
     * @param int $views
322
     * @return AlbumInterface
323
     */
324 1
    public function setViews($views)
325
    {
326 1
        $this->views = $views;
327
328 1
        return $this;
329
    }
330
331
    /**
332
     * @return int
333
     */
334 1
    public function getViews()
335
    {
336 1
        return $this->views;
337
    }
338
339
    /**
340
     * @param string $link
341
     * @return AlbumInterface
342
     */
343 1
    public function setLink($link)
344
    {
345 1
        $this->link = $link;
346
347 1
        return $this;
348
    }
349
350
    /**
351
     * @return string
352
     */
353 1
    public function getLink()
354
    {
355 1
        return $this->link;
356
    }
357
358
    /**
359
     * @param bool $favorite
360
     * @return AlbumInterface
361
     */
362 1
    public function setFavorite($favorite)
363
    {
364 1
        $this->favorite = $favorite;
365
366 1
        return $this;
367
    }
368
369
    /**
370
     * @return bool
371
     */
372 1
    public function isFavorite()
373
    {
374 1
        return $this->favorite;
375
    }
376
377
    /**
378
     * @param bool $nsfw
379
     * @return AlbumInterface
380
     */
381 1
    public function setNsfw($nsfw)
382
    {
383 1
        $this->nsfw = $nsfw;
384
385 1
        return $this;
386
    }
387
388
    /**
389
     * @return bool
390
     */
391 1
    public function isNsfw()
392
    {
393 1
        return $this->nsfw;
394
    }
395
396
    /**
397
     * @param string $section
398
     * @return AlbumInterface
399
     */
400 1
    public function setSection($section)
401
    {
402 1
        $this->section = $section;
403
404 1
        return $this;
405
    }
406
407
    /**
408
     * @return mixed
409
     */
410 1
    public function getSection()
411
    {
412 1
        return $this->section;
413
    }
414
415
    /**
416
     * @param int $order
417
     * @return AlbumInterface
418
     */
419 1
    public function setOrder($order)
420
    {
421 1
        $this->order = $order;
422
423 1
        return $this;
424
    }
425
426
    /**
427
     * @return int
428
     */
429 1
    public function getOrder()
430
    {
431 1
        return $this->order;
432
    }
433
434
    /**
435
     * @param string $deleteHash
436
     * @return AlbumInterface
437
     */
438 1
    public function setDeleteHash($deleteHash)
439
    {
440 1
        $this->deleteHash = $deleteHash;
441
442 1
        return $this;
443
    }
444
445
    /**
446
     * @return string
447
     */
448 1
    public function getDeleteHash()
449
    {
450 1
        return $this->deleteHash;
451
    }
452
453
    /**
454
     * @param int $imagesCount
455
     * @return AlbumInterface
456
     */
457 1
    public function setImagesCount($imagesCount)
458
    {
459 1
        $this->imagesCount = $imagesCount;
460
461 1
        return $this;
462
    }
463
464
    /**
465
     * @return int
466
     */
467 1
    public function getImagesCount()
468
    {
469 1
        return $this->imagesCount;
470
    }
471
472
    /**
473
     * @param ImageInterface[] $images
474
     * @return AlbumInterface
475
     */
476 1
    public function setImages($images)
477
    {
478 1
        $this->images = $images;
479
480 1
        return $this;
481
    }
482
483
    /**
484
     * @return ImageInterface[]
485
     */
486
    public function getImages()
487
    {
488
        return $this->images;
489
    }
490
}