Artist   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 19
lcom 2
cbo 2
dl 0
loc 116
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 18 12
A getName() 0 4 1
A getScore() 0 4 2
A getType() 0 4 1
A getReleases() 0 8 2
A getId() 0 4 1
1
<?php
2
3
namespace MusicBrainz;
4
5
/**
6
 * Represents a MusicBrainz artist object
7
 * @package MusicBrainz
8
 */
9
class Artist
10
{
11
    /**
12
     * @var string
13
     */
14
    public $id;
15
    /**
16
     * @var string
17
     */
18
    public $name;
19
    /**
20
     * @var MusicBrainz
21
     */
22
    protected $brainz;
23
    /**
24
     * @var string
25
     */
26
    private $type;
27
    /**
28
     * @var string
29
     */
30
    private $sortName;
31
    /**
32
     * @var string
33
     */
34
    private $gender;
35
    /**
36
     * @var string
37
     */
38
    private $country;
39
    /**
40
     * @var string
41
     */
42
    private $beginDate;
43
    /**
44
     * @var string
45
     */
46
    private $endDate;
47
    /**
48
     * @var array
49
     */
50
    private $data;
51
    /**
52
     * @var array
53
     */
54
    private $releases;
55
56
    /**
57
     * @param array       $artist
58
     * @param MusicBrainz $brainz
59
     *
60
     * @throws Exception
61
     */
62
    public function __construct(array $artist, MusicBrainz $brainz)
63
    {
64
        if (!isset($artist['id']) || isset($artist['id']) && !$brainz->isValidMBID($artist['id'])) {
65
            throw new Exception('Can not create artist object. Missing valid MBID');
66
        }
67
68
        $this->data   = $artist;
69
        $this->brainz = $brainz;
70
71
        $this->id        = isset($artist['id']) ? (string)$artist['id'] : '';
72
        $this->type      = isset($artist['type']) ? (string)$artist['type'] : '';
73
        $this->name      = isset($artist['name']) ? (string)$artist['name'] : '';
74
        $this->sortName  = isset($artist['sort-name']) ? (string)$artist['sort-name'] : '';
75
        $this->gender    = isset($artist['gender']) ? (string)$artist['gender'] : '';
76
        $this->country   = isset($artist['country']) ? (string)$artist['country'] : '';
77
        $this->beginDate = isset($artist['life-span']['begin']) ? $artist['life-span']['begin'] : NULL;
78
        $this->endDate   = isset($artist['life-span']['ended']) ? $artist['life-span']['ended'] : NULL;
79
    }
80
81
    /**
82
     * @return mixed
83
     */
84
    public function getName()
85
    {
86
        return $this->name;
87
    }
88
89
    /**
90
     * @return int
91
     */
92
    public function getScore()
93
    {
94
        return isset($this->data['score']) ? (int)$this->data['score'] : 0;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getType()
101
    {
102
        return $this->type;
103
    }
104
105
    /**
106
     * @return array
107
     */
108
    public function getReleases()
109
    {
110
        if (NULL === $this->releases) {
111
            $this->releases = $this->brainz->browseRelease('artist', $this->getId());
112
        }
113
114
        return $this->releases;
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function getId()
121
    {
122
        return $this->id;
123
    }
124
}
125
126