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

SongInfo::getDuration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
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 SongInfo
15
{
16
    /**
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * @var string|null
23
     */
24
    private $mbid;
25
26
    /**
27
     * @var int|null
28
     */
29
    private $duration;
30
31
    /**
32
     * @var Artist|null
33
     */
34
    private $artist;
35
36
    /**
37
     * @var int
38
     */
39
    private $listeners;
40
41
    /**
42
     * @var int
43
     */
44
    private $playcount;
45
46
    /**
47
     * @var Tag[]
48
     */
49
    private $topTags;
50
51
    /**
52
     * SongInfo constructor.
53
     *
54
     * @param string      $name
55
     * @param null|string $mbid
56
     * @param int|null    $duration
57
     * @param Artist|null $artist
58
     * @param int         $listeners
59
     * @param int         $playcount
60
     * @param Tag[]       $topTags
61
     */
62
    public function __construct(
63
        string $name,
64
        ?string $mbid,
65
        ?int $duration,
66
        ?Artist $artist,
67
        int $listeners,
68
        int $playcount,
69
        array $topTags
70
    ) {
71
        $this->name      = $name;
72
        $this->mbid      = $mbid;
73
        $this->duration  = $duration;
74
        $this->artist    = $artist;
75
        $this->listeners = $listeners;
76
        $this->playcount = $playcount;
77
        $this->topTags   = $topTags;
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 int|null
98
     */
99
    public function getDuration(): ?int
100
    {
101
        return $this->duration;
102
    }
103
104
    /**
105
     * @return Artist|null
106
     */
107
    public function getArtist(): ?Artist
108
    {
109
        return $this->artist;
110
    }
111
112
    /**
113
     * @return int
114
     */
115
    public function getListeners(): int
116
    {
117
        return $this->listeners;
118
    }
119
120
    /**
121
     * @return int
122
     */
123
    public function getPlaycount(): int
124
    {
125
        return $this->playcount;
126
    }
127
128
    /**
129
     * @return Tag[]
130
     */
131
    public function getTopTags(): array
132
    {
133
        return $this->topTags;
134
    }
135
136
    /**
137
     * @param array $data
138
     *
139
     * @return SongInfo
140
     */
141
    public static function fromApi(array $data): self
142
    {
143
        $tags   = [];
144
145
        if (isset($data['toptags']['tag'])) {
146
            foreach ((array) $data['toptags']['tag'] as $tag) {
147
                $tags[] = Tag::fromApi($tag);
148
            }
149
        }
150
151
        $artist = null;
152
153
        if (isset($data['artist'])) {
154
            if (is_array($data['artist'])) {
155
                $artist = Artist::fromApi($data['artist']);
156
            } else {
157
                $artist = new Artist($data['artist'], null, [], null);
158
            }
159
        }
160
161
        return new self(
162
            $data['name'],
163
            $data['mbid'] ?? null,
164
            isset($data['duration']) ? (int) $data['duration'] : null,
165
            $artist,
166
            isset($data['listeners']) ? (int) $data['listeners'] : 0,
167
            isset($data['playcount']) ? (int) $data['playcount'] : 0,
168
            $tags
169
        );
170
    }
171
}
172