ReleaseGroup   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 9.86 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 7
loc 71
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 2
A getId() 0 4 1
A getTitle() 0 4 1
A getScore() 0 4 1
A getReleases() 0 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace MusicBrainz;
4
5
/**
6
 * Represents a MusicBrainz release group
7
 *
8
 */
9
class ReleaseGroup
10
{
11
    /**
12
     * @var string
13
     */
14
    public $id;
15
    /**
16
     * @var array
17
     */
18
    private $data;
19
    /**
20
     * @var MusicBrainz
21
     */
22
    private $brainz;
23
    /**
24
     * @var Release[]
25
     */
26
    private $releases = array();
27
28
    /**
29
     * @param array       $releaseGroup
30
     * @param MusicBrainz $brainz
31
     */
32 View Code Duplication
    public function __construct(array $releaseGroup, MusicBrainz $brainz)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        $this->data   = $releaseGroup;
35
        $this->brainz = $brainz;
36
37
        $this->id = isset($releaseGroup['id']) ? (string)$releaseGroup['id'] : '';
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getId()
44
    {
45
        return $this->id;
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getTitle()
52
    {
53
        return $this->data['title'];
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59
    public function getScore()
60
    {
61
        return $this->data['score'];
62
    }
63
64
    /**
65
     * @return Release[]
66
     */
67
    public function getReleases()
68
    {
69
        if (!empty($this->releases)) {
70
            return $this->releases;
71
        }
72
73
        foreach ($this->data['releases'] as $release) {
74
            array_push($this->releases, new Release($release, $this->brainz));
75
        }
76
77
        return $this->releases;
78
    }
79
}
80