GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 547017...c67bb4 )
by Christian
04:20
created

ArtistInfo   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 16
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 155
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A getName() 0 4 1
A getMbid() 0 4 1
A getImage() 0 4 1
A getUrl() 0 4 1
A getPlaycount() 0 4 1
A getTagcount() 0 4 1
A getTags() 0 4 1
C fromApi() 0 27 8
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\LastFm\Model;
13
14
final class ArtistInfo
15
{
16
    /**
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * @var string|null
23
     */
24
    private $mbid;
25
26
    /**
27
     * @var Image[]
28
     */
29
    private $image;
30
31
    /**
32
     * @var string|null
33
     */
34
    private $url;
35
36
    /**
37
     * @var int
38
     */
39
    private $playcount;
40
41
    /**
42
     * @var int
43
     */
44
    private $tagcount;
45
46
    /**
47
     * @var Tag[]
48
     */
49
    private $tags;
50
51
    /**
52
     * ArtistInfo constructor.
53
     *
54
     * @param string      $name
55
     * @param null|string $mbid
56
     * @param Image[]     $image
57
     * @param null|string $url
58
     * @param int         $playcount
59
     * @param int         $tagcount
60
     * @param Tag[]       $tags
61
     */
62
    public function __construct(
63
        string $name,
64
        ?string $mbid,
65
        array $image,
66
        ?string $url,
67
        int $playcount,
68
        int $tagcount,
69
        array $tags
70
    ) {
71
        $this->name      = $name;
72
        $this->mbid      = $mbid;
73
        $this->image     = $image;
74
        $this->url       = $url;
75
        $this->playcount = $playcount;
76
        $this->tagcount  = $tagcount;
77
        $this->tags      = $tags;
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getName(): string
84
    {
85
        return $this->name;
86
    }
87
88
    /**
89
     * @return null|string
90
     */
91
    public function getMbid(): ?string
92
    {
93
        return $this->mbid;
94
    }
95
96
    /**
97
     * @return Image[]
98
     */
99
    public function getImage(): array
100
    {
101
        return $this->image;
102
    }
103
104
    /**
105
     * @return null|string
106
     */
107
    public function getUrl(): ?string
108
    {
109
        return $this->url;
110
    }
111
112
    /**
113
     * @return int
114
     */
115
    public function getPlaycount(): int
116
    {
117
        return $this->playcount;
118
    }
119
120
    /**
121
     * @return int
122
     */
123
    public function getTagcount(): int
124
    {
125
        return $this->tagcount;
126
    }
127
128
    /**
129
     * @return Tag[]
130
     */
131
    public function getTags(): array
132
    {
133
        return $this->tags;
134
    }
135
136
    /**
137
     * @param array $data
138
     *
139
     * @return ArtistInfo
140
     */
141
    public static function fromApi(array $data): self
142
    {
143
        $images = [];
144
        $tags   = [];
145
146
        if (array_key_exists('image', $data)) {
147
            foreach ((array) $data['image'] as $image) {
148
                $images[] = new Image($image['#text']);
149
            }
150
        }
151
152
        if (array_key_exists('tags', $data) && array_key_exists('tag', $data['tags'])) {
153
            foreach ((array) $data['tags']['tag'] as $tag) {
154
                $tags[] = Tag::fromApi($tag);
155
            }
156
        }
157
158
        return new self(
159
            $data['name'],
160
            $data['mbid'] ?? null,
161
            $images,
162
            $data['url'] ?? null,
163
            isset($data['playcount']) ? (int) $data['playcount'] : 0,
164
            isset($data['tagcount']) ? (int) $data['tagcount'] : 0,
165
            $tags
166
        );
167
    }
168
}
169