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 ( fc424a...ea923b )
by Christian
06:24
created

Setlist   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 218
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 20
lcom 0
cbo 4
dl 0
loc 218
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 23 1
A getId() 0 4 1
A getArtist() 0 4 1
A getVenue() 0 4 1
A getTour() 0 4 1
A getSets() 0 4 1
A getInfo() 0 4 1
A getUrl() 0 4 1
A getVersionId() 0 4 1
A getEventDate() 0 4 1
A getUpdateDate() 0 4 1
D fromApi() 0 42 9
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\SetlistFm\Model;
13
14
final class Setlist
15
{
16
    /**
17
     * @var string
18
     */
19
    private $id;
20
21
    /**
22
     * @var Artist|null
23
     */
24
    private $artist;
25
26
    /**
27
     * @var Venue|null
28
     */
29
    private $venue;
30
31
    /**
32
     * @var Tour|null
33
     */
34
    private $tour;
35
36
    /**
37
     * @var Set[]
38
     */
39
    private $sets;
40
41
    /**
42
     * @var string|null
43
     */
44
    private $info;
45
46
    /**
47
     * @var string|null
48
     */
49
    private $url;
50
51
    /**
52
     * @var string|null
53
     */
54
    private $versionId;
55
56
    /**
57
     * @var \DateTime
58
     */
59
    private $eventDate;
60
61
    /**
62
     * @var \DateTime|null
63
     */
64
    private $updateDate;
65
66
    /**
67
     * Setlist constructor.
68
     *
69
     * @param string         $id
70
     * @param Artist|null    $artist
71
     * @param Venue|null     $venue
72
     * @param Tour|null      $tour
73
     * @param Set[]          $sets
74
     * @param null|string    $info
75
     * @param null|string    $url
76
     * @param null|string    $versionId
77
     * @param \DateTime      $eventDate
78
     * @param \DateTime|null $updateDate
79
     */
80
    public function __construct(
81
        string $id,
82
        ?Artist $artist,
83
        ?Venue $venue,
84
        ?Tour $tour,
85
        array $sets,
86
        ?string $info,
87
        ?string $url,
88
        ?string $versionId,
89
        \DateTime $eventDate,
90
        ?\DateTime $updateDate
91
    ) {
92
        $this->id         = $id;
93
        $this->artist     = $artist;
94
        $this->venue      = $venue;
95
        $this->tour       = $tour;
96
        $this->sets       = $sets;
97
        $this->info       = $info;
98
        $this->url        = $url;
99
        $this->versionId  = $versionId;
100
        $this->eventDate  = $eventDate;
101
        $this->updateDate = $updateDate;
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    public function getId(): string
108
    {
109
        return $this->id;
110
    }
111
112
    /**
113
     * @return Artist|null
114
     */
115
    public function getArtist(): ?Artist
116
    {
117
        return $this->artist;
118
    }
119
120
    /**
121
     * @return Venue|null
122
     */
123
    public function getVenue(): ?Venue
124
    {
125
        return $this->venue;
126
    }
127
128
    /**
129
     * @return Tour|null
130
     */
131
    public function getTour(): ?Tour
132
    {
133
        return $this->tour;
134
    }
135
136
    /**
137
     * @return Set[]
138
     */
139
    public function getSets(): array
140
    {
141
        return $this->sets;
142
    }
143
144
    /**
145
     * @return null|string
146
     */
147
    public function getInfo(): ?string
148
    {
149
        return $this->info;
150
    }
151
152
    /**
153
     * @return null|string
154
     */
155
    public function getUrl(): ?string
156
    {
157
        return $this->url;
158
    }
159
160
    /**
161
     * @return null|string
162
     */
163
    public function getVersionId(): ?string
164
    {
165
        return $this->versionId;
166
    }
167
168
    /**
169
     * @return \DateTime
170
     */
171
    public function getEventDate(): \DateTime
172
    {
173
        return $this->eventDate;
174
    }
175
176
    /**
177
     * @return \DateTime|null
178
     */
179
    public function getUpdateDate(): ?\DateTime
180
    {
181
        return $this->updateDate;
182
    }
183
184
    /**
185
     * @param array $data
186
     *
187
     * @return Setlist
188
     */
189
    public static function fromApi(array $data): self
190
    {
191
        $artist = null;
192
        $venue  = null;
193
        $tour   = null;
194
        $sets   = [];
195
196
        if (array_key_exists('artist', $data)) {
197
            $artist = Artist::fromApi($data['artist']);
198
        }
199
        if (array_key_exists('venue', $data)) {
200
            $venue = Venue::fromApi($data['venue']);
201
        }
202
        if (array_key_exists('tour', $data)) {
203
            $tour = Tour::fromApi($data['tour']);
204
        }
205
206
        $setData = [];
207
208
        if (array_key_exists('sets', $data) && array_key_exists('set', $data['sets'])) {
209
            $setData = $data['sets']['set'];
210
        } elseif (array_key_exists('set', $data)) {
211
            $setData = $data['set'];
212
        }
213
214
        foreach ($setData as $set) {
215
            $sets[] = Set::fromApi($set);
216
        }
217
218
        return new self(
219
            $data['id'],
220
            $artist,
221
            $venue,
222
            $tour,
223
            $sets,
224
            $data['info'] ?? null,
225
            $data['url'] ?? null,
226
            $data['versionId'] ?? null,
227
            new \DateTime($data['eventDate']),
228
            $data['lastUpdated'] ? new \DateTime($data['lastUpdated']) : null
229
        );
230
    }
231
}
232