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 ( e30cbf...f60278 )
by Christian
01:38
created

Album::createImagesFromApi()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 2
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 Album
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
     * @param string|null $name
43
     * @param Artist|null $artist
44
     * @param string|null $mbid
45
     * @param string|null $url
46
     * @param Image[]     $images
47
     */
48
    public function __construct(?string $name, ?Artist $artist, ?string $mbid, ?string $url, array $images)
49
    {
50
        $this->name   = $name;
51
        $this->artist = $artist;
52
        $this->mbid   = $mbid;
53
        $this->url    = $url;
54
        $this->images = $images;
55
    }
56
57
    /**
58
     * @return string|null
59
     */
60
    public function getName(): ?string
61
    {
62
        return $this->name;
63
    }
64
65
    /**
66
     * @return Artist|null
67
     */
68
    public function getArtist(): ?Artist
69
    {
70
        return $this->artist;
71
    }
72
73
    /**
74
     * @return string|null
75
     */
76
    public function getMbid(): ?string
77
    {
78
        return $this->mbid;
79
    }
80
81
    /**
82
     * @return string|null
83
     */
84
    public function getUrl(): ?string
85
    {
86
        return $this->url;
87
    }
88
89
    /**
90
     * @return Image[]
91
     */
92
    public function getImages(): array
93
    {
94
        return $this->images;
95
    }
96
97
    /**
98
     * @param array $data
99
     *
100
     * @return Album
101
     */
102
    public static function fromApi(array $data): self
103
    {
104
        $images = self::createImagesFromApi($data);
105
106
        return new self(
107
            $data['name'],
108
            $data['artist'] ? Artist::fromApi($data['artist']) : null,
109
            $data['mbid'] ?? null,
110
            $data['url'] ?? null,
111
            $images
112
        );
113
    }
114
115
    /**
116
     * @param array $data
117
     *
118
     * @return array
119
     */
120
    private static function createImagesFromApi(array $data): array
121
    {
122
        $images = [];
123
124
        if (\array_key_exists('image', $data)) {
125
            foreach ((array) $data['image'] as $image) {
126
                $images[] = new Image($image['#text']);
127
            }
128
        }
129
130
        return $images;
131
    }
132
}
133