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.

AlbumInfo::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 AlbumInfo
15
{
16
    /**
17
     * @var string|null
18
     */
19
    private $name;
20
21
    /**
22
     * @var Artist|null
23
     */
24
    private $artist;
25
26
    /**
27
     * @var string|null
28
     */
29
    private $mbid;
30
31
    /**
32
     * @var string|null
33
     */
34
    private $url;
35
36
    /**
37
     * @var Image[]
38
     */
39
    private $images;
40
41
    /**
42
     * @var int
43
     */
44
    private $listeners;
45
46
    /**
47
     * @var int
48
     */
49
    private $playcount;
50
51
    /**
52
     * @var Song[]
53
     */
54
    private $tracks;
55
56
    /**
57
     * @var Tag[]
58
     */
59
    private $tags;
60
61
    /**
62
     * @var string|null
63
     */
64
    private $wikiSummary;
65
66
    /**
67
     * @param Image[] $images
68
     * @param Song[]  $tracks
69
     * @param Tag[]   $tags
70
     */
71
    public function __construct(
72
        ?string $name,
73
        ?Artist $artist,
74
        ?string $mbid,
75
        ?string $url,
76
        array $images,
77
        int $listeners,
78
        int $playcount,
79
        array $tracks,
80
        array $tags,
81
        ?string $wikiSummary
82
    ) {
83
        $this->name         = $name;
84
        $this->artist       = $artist;
85
        $this->mbid         = $mbid;
86
        $this->url          = $url;
87
        $this->images       = $images;
88
        $this->listeners    = $listeners;
89
        $this->playcount    = $playcount;
90
        $this->tracks       = $tracks;
91
        $this->tags         = $tags;
92
        $this->wikiSummary  = $wikiSummary;
93
    }
94
95
    public function getName(): ?string
96
    {
97
        return $this->name;
98
    }
99
100
    public function getArtist(): ?Artist
101
    {
102
        return $this->artist;
103
    }
104
105
    public function getMbid(): ?string
106
    {
107
        return $this->mbid;
108
    }
109
110
    public function getUrl(): ?string
111
    {
112
        return $this->url;
113
    }
114
115
    /**
116
     * @return Image[]
117
     */
118
    public function getImage(): array
119
    {
120
        return $this->images;
121
    }
122
123
    public function getListeners(): int
124
    {
125
        return $this->listeners;
126
    }
127
128
    public function getPlaycount(): int
129
    {
130
        return $this->playcount;
131
    }
132
133
    /**
134
     * @return Song[]
135
     */
136
    public function getTracks(): array
137
    {
138
        return $this->tracks;
139
    }
140
141
    /**
142
     * @return Tag[]
143
     */
144
    public function getTags(): array
145
    {
146
        return $this->tags;
147
    }
148
149
    public function getWikiSummary(): ?string
150
    {
151
        return $this->wikiSummary;
152
    }
153
154
    /**
155
     * @return AlbumInfo
156
     */
157
    public static function fromApi(array $data): self
158
    {
159
        $images = self::createImagesFromApi($data);
160
        $tracks = self::createTracksFromApi($data);
161
        $tags   = self::createTagsFromApi($data);
162
163
        return new self(
164
            $data['name'],
165
            new Artist($data['artist'], null, [], null),
166
            $data['mbid'] ?? null,
167
            $data['url'] ?? null,
168
            $images,
169
            $data['listeners'] ?? 0,
170
            $data['playcount'] ?? 0,
171
            $tracks,
172
            $tags,
173
            $data['wiki']['summary'] ?? null
174
        );
175
    }
176
177
    private static function createImagesFromApi(array $data): array
178
    {
179
        $images = [];
180
181
        if (\array_key_exists('image', $data)) {
182
            foreach ((array) $data['image'] as $image) {
183
                $images[] = new Image($image['#text']);
184
            }
185
        }
186
187
        return $images;
188
    }
189
190
    private static function createTracksFromApi(array $data): array
191
    {
192
        $tracks = [];
193
194
        if (\array_key_exists('tracks', $data) && \array_key_exists('track', $data['tracks'])) {
195
            foreach ((array) $data['tracks']['track'] as $track) {
196
                $tracks[] = Song::fromApi($track);
197
            }
198
        }
199
200
        return $tracks;
201
    }
202
203
    private static function createTagsFromApi(array $data): array
204
    {
205
        $tags = [];
206
207
        if (\array_key_exists('tags', $data) && \array_key_exists('tag', $data['tags'])) {
208
            foreach ((array) $data['tags']['tag'] as $tag) {
209
                $tags[] = Tag::fromApi($tag);
210
            }
211
        }
212
213
        return $tags;
214
    }
215
}
216