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.

ArtistInfo   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 2
dl 0
loc 171
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 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 getBioSummary() 0 4 1
A getBioContent() 0 4 1
A getTagcount() 0 4 1
A getTags() 0 4 1
A fromApi() 0 17 3
A createImagesFromApi() 0 12 3
A createTagsFromApi() 0 12 4
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 string|null
43
     */
44
    private $bioSummary;
45
46
    /**
47
     * @var string|null
48
     */
49
    private $bioContent;
50
51
    /**
52
     * @var int
53
     */
54
    private $tagcount;
55
56
    /**
57
     * @var Tag[]
58
     */
59
    private $tags;
60
61
    /**
62
     * @param Image[] $image
63
     * @param Tag[]   $tags
64
     */
65
    public function __construct(
66
        string $name,
67
        ?string $mbid,
68
        array $image,
69
        ?string $url,
70
        int $playcount,
71
        ?string $bioSummary,
72
        ?string $bioContent,
73
        int $tagcount,
74
        array $tags
75
    ) {
76
        $this->name       = $name;
77
        $this->mbid       = $mbid;
78
        $this->image      = $image;
79
        $this->url        = $url;
80
        $this->playcount  = $playcount;
81
        $this->bioSummary = $bioSummary;
82
        $this->bioContent = $bioContent;
83
        $this->tagcount   = $tagcount;
84
        $this->tags       = $tags;
85
    }
86
87
    public function getName(): string
88
    {
89
        return $this->name;
90
    }
91
92
    public function getMbid(): ?string
93
    {
94
        return $this->mbid;
95
    }
96
97
    /**
98
     * @return Image[]
99
     */
100
    public function getImage(): array
101
    {
102
        return $this->image;
103
    }
104
105
    public function getUrl(): ?string
106
    {
107
        return $this->url;
108
    }
109
110
    public function getPlaycount(): int
111
    {
112
        return $this->playcount;
113
    }
114
115
    public function getBioSummary(): ?string
116
    {
117
        return $this->bioSummary;
118
    }
119
120
    public function getBioContent(): ?string
121
    {
122
        return $this->bioContent;
123
    }
124
125
    public function getTagcount(): int
126
    {
127
        return $this->tagcount;
128
    }
129
130
    /**
131
     * @return Tag[]
132
     */
133
    public function getTags(): array
134
    {
135
        return $this->tags;
136
    }
137
138
    /**
139
     * @return ArtistInfo
140
     */
141
    public static function fromApi(array $data): self
142
    {
143
        $images = self::createImagesFromApi($data);
144
        $tags   = self::createTagsFromApi($data);
145
146
        return new self(
147
            $data['name'],
148
            $data['mbid'] ?? null,
149
            $images,
150
            $data['url'] ?? null,
151
            isset($data['playcount']) ? (int) $data['playcount'] : 0,
152
            $data['bio']['summary'] ?? null,
153
            $data['bio']['content'] ?? null,
154
            isset($data['tagcount']) ? (int) $data['tagcount'] : 0,
155
            $tags
156
        );
157
    }
158
159
    private static function createImagesFromApi(array $data): array
160
    {
161
        $images = [];
162
163
        if (\array_key_exists('image', $data)) {
164
            foreach ((array) $data['image'] as $image) {
165
                $images[] = new Image($image['#text']);
166
            }
167
        }
168
169
        return $images;
170
    }
171
172
    private static function createTagsFromApi(array $data): array
173
    {
174
        $tags = [];
175
176
        if (\array_key_exists('tags', $data) && \array_key_exists('tag', $data['tags'])) {
177
            foreach ((array) $data['tags']['tag'] as $tag) {
178
                $tags[] = Tag::fromApi($tag);
179
            }
180
        }
181
182
        return $tags;
183
    }
184
}
185