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

AlbumInfo::fromApi()   D

Complexity

Conditions 9
Paths 8

Size

Total Lines 37
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 37
rs 4.909
cc 9
eloc 24
nc 8
nop 1
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
     * AlbumInfo constructor.
68
     *
69
     * @param null|string $name
70
     * @param Artist|null $artist
71
     * @param null|string $mbid
72
     * @param null|string $url
73
     * @param Image[]     $images
74
     * @param int         $listeners
75
     * @param int         $playcount
76
     * @param Song[]      $tracks
77
     * @param Tag[]       $tags
78
     * @param null|string $wikiSummary
79
     */
80
    public function __construct(
81
        ?string $name,
82
        ?Artist $artist,
83
        ?string $mbid,
84
        ?string $url,
85
        array $images,
86
        int $listeners,
87
        int $playcount,
88
        array $tracks,
89
        array $tags,
90
        ?string $wikiSummary
91
    ) {
92
        $this->name         = $name;
93
        $this->artist       = $artist;
94
        $this->mbid         = $mbid;
95
        $this->url          = $url;
96
        $this->images       = $images;
97
        $this->listeners    = $listeners;
98
        $this->playcount    = $playcount;
99
        $this->tracks       = $tracks;
100
        $this->tags         = $tags;
101
        $this->wikiSummary  = $wikiSummary;
102
    }
103
104
    /**
105
     * @return null|string
106
     */
107
    public function getName(): ?string
108
    {
109
        return $this->name;
110
    }
111
112
    /**
113
     * @return Artist|null
114
     */
115
    public function getArtist(): ?Artist
116
    {
117
        return $this->artist;
118
    }
119
120
    /**
121
     * @return null|string
122
     */
123
    public function getMbid(): ?string
124
    {
125
        return $this->mbid;
126
    }
127
128
    /**
129
     * @return null|string
130
     */
131
    public function getUrl(): ?string
132
    {
133
        return $this->url;
134
    }
135
136
    /**
137
     * @return Image[]
138
     */
139
    public function getImage(): array
140
    {
141
        return $this->images;
142
    }
143
144
    /**
145
     * @return int
146
     */
147
    public function getListeners(): int
148
    {
149
        return $this->listeners;
150
    }
151
152
    /**
153
     * @return int
154
     */
155
    public function getPlaycount(): int
156
    {
157
        return $this->playcount;
158
    }
159
160
    /**
161
     * @return Song[]
162
     */
163
    public function getTracks(): array
164
    {
165
        return $this->tracks;
166
    }
167
168
    /**
169
     * @return Tag[]
170
     */
171
    public function getTags(): array
172
    {
173
        return $this->tags;
174
    }
175
176
    /**
177
     * @return null|string
178
     */
179
    public function getWikiSummary(): ?string
180
    {
181
        return $this->wikiSummary;
182
    }
183
184
    /**
185
     * @param array $data
186
     *
187
     * @return AlbumInfo
188
     */
189
    public static function fromApi(array $data): self
190
    {
191
        $images = [];
192
        $tracks = [];
193
        $tags   = [];
194
195
        if (array_key_exists('image', $data)) {
196
            foreach ((array) $data['image'] as $image) {
197
                $images[] = new Image($image['#text']);
198
            }
199
        }
200
201
        if (array_key_exists('tracks', $data) && array_key_exists('track', $data['tracks'])) {
202
            foreach ((array) $data['tracks']['track'] as $track) {
203
                $tracks[] = Song::fromApi($track);
204
            }
205
        }
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 new self(
214
            $data['name'],
215
            new Artist($data['artist'], null, [], null),
216
            $data['mbid'] ?? null,
217
            $data['url'] ?? null,
218
            $images,
219
            $data['listeners'] ?? 0,
220
            $data['playcount'] ?? 0,
221
            $tracks,
222
            $tags,
223
            $data['wiki']['summary'] ?? null
224
        );
225
    }
226
}
227