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.

SetlistTest::testFromApi()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 113

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 113
rs 8
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\SetlistFm\Tests\Model;
11
12
use Core23\SetlistFm\Model\Setlist;
13
use DateTime;
14
use PHPUnit\Framework\TestCase;
15
16
final class SetlistTest extends TestCase
17
{
18
    public function testFromApi(): void
19
    {
20
        $data = <<<'EOD'
21
            {
22
               "id" : "63de4613",
23
               "versionId" : "7be1aaa0",
24
               "eventDate" : "23-08-1964",
25
               "lastUpdated" : "2013-10-20T05:18:08.000+0000",
26
               "artist" : {
27
                  "mbid" : "b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d",
28
                  "tmid" : 735610,
29
                  "name" : "The Beatles",
30
                  "sortName" : "Beatles, The",
31
                  "disambiguation" : "",
32
                  "url" : "https://www.setlist.fm/setlists/the-beatles-23d6a88b.html"
33
               },
34
               "venue" : {
35
                  "id" : "33d62cf9",
36
                  "name" : "Hollywood Bowl",
37
                  "city" : {
38
                     "id" : "5368361",
39
                     "name" : "Los Angeles",
40
                     "state" : "California",
41
                     "stateCode" : "CA",
42
                     "coords" : {
43
                        "lat" : 34.052,
44
                        "long" : -118.244
45
                     },
46
                     "country" : {
47
                        "code" : "US",
48
                        "name" : "United States"
49
                     }
50
                  },
51
                  "url" : "https://www.setlist.fm/venue/hollywood-bowl-los-angeles-ca-usa-33d62cf9.html"
52
               },
53
               "tour" : {
54
                  "name" : "North American Tour 1964"
55
               },
56
               "sets" : {
57
                  "set" : [ {
58
                     "song" : [ {
59
                        "name" : "Twist and Shout",
60
                        "cover" : {
61
                           "mbid" : "f18eac60-48d2-4d2b-b432-e43ce7e31d36",
62
                           "name" : "The Top Notes",
63
                           "sortName" : "Top Notes, The",
64
                           "url" : "https://www.setlist.fm/setlists/the-top-notes-53d433dd.html"
65
                        }
66
                     }, {
67
                        "name" : "You Can't Do That"
68
                     }, {
69
                        "name" : "All My Loving"
70
                     }, {
71
                        "name" : "She Loves You"
72
                     }, {
73
                        "name" : "Things We Said Today"
74
                     }, {
75
                        "name" : "Roll Over Beethoven",
76
                        "cover" : {
77
                           "mbid" : "592a3b6d-c42b-4567-99c9-ecf63bd66499",
78
                           "tmid" : 734540,
79
                           "name" : "Chuck Berry",
80
                           "sortName" : "Berry, Chuck",
81
                           "disambiguation" : "",
82
                           "url" : "https://www.setlist.fm/setlists/chuck-berry-63d6a2b7.html"
83
                        }
84
                     }, {
85
                        "name" : "Can't Buy Me Love"
86
                     }, {
87
                        "name" : "If I Fell"
88
                     }, {
89
                        "name" : "I Want to Hold Your Hand"
90
                     }, {
91
                        "name" : "Boys",
92
                        "cover" : {
93
                           "mbid" : "a8540ea0-1a74-4c22-8b70-1348a77a74a0",
94
                           "name" : "The Shirelles",
95
                           "sortName" : "Shirelles, The",
96
                           "disambiguation" : "",
97
                           "url" : "https://www.setlist.fm/setlists/the-shirelles-bd69d7a.html"
98
                        }
99
                     }, {
100
                        "name" : "A Hard Day's Night"
101
                     }, {
102
                        "name" : "Long Tall Sally",
103
                        "cover" : {
104
                           "mbid" : "95c2339b-8277-49a6-9aaf-08d8eeeaa0be",
105
                           "tmid" : 735520,
106
                           "name" : "Little Richard",
107
                           "sortName" : "Little Richard",
108
                           "disambiguation" : "",
109
                           "url" : "https://www.setlist.fm/setlists/little-richard-4bd6af2e.html"
110
                        }
111
                     } ]
112
                  } ]
113
               },
114
               "info" : "Recorded and published as 'The Beatles at the Hollywood Bowl'",
115
               "url" : "https://www.setlist.fm/setlist/the-beatles/1964/hollywood-bowl-los-angeles-ca-63de4613.html"
116
            }
117
EOD;
118
119
        $setlist = Setlist::fromApi(json_decode($data, true));
120
        static::assertSame('63de4613', $setlist->getId());
121
        static::assertSame('7be1aaa0', $setlist->getVersionId());
122
        static::assertNotNull($setlist->getVenue());
123
        static::assertNotNull($setlist->getArtist());
124
        static::assertEquals(new DateTime('23-08-1964'), $setlist->getEventDate(), '', 0);
125
        static::assertSame('Recorded and published as \'The Beatles at the Hollywood Bowl\'', $setlist->getInfo());
126
        static::assertCount(1, $setlist->getSets());
127
        static::assertNotNull($setlist->getTour());
128
        static::assertEquals(new DateTime('2013-10-20T05:18:08.000+0000'), $setlist->getUpdateDate(), '', 0);
129
        static::assertSame('https://www.setlist.fm/setlist/the-beatles/1964/hollywood-bowl-los-angeles-ca-63de4613.html', $setlist->getUrl());
130
    }
131
132
    public function testFromApiWithSingleSet(): void
133
    {
134
        $data = <<<'EOD'
135
            {
136
               "id" : "63de4613",
137
               "versionId" : "7be1aaa0",
138
               "eventDate" : "23-08-1964",
139
               "lastUpdated" : "2013-10-20T05:18:08.000+0000",
140
               "artist" : {
141
                  "mbid" : "b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d",
142
                  "tmid" : 735610,
143
                  "name" : "The Beatles",
144
                  "sortName" : "Beatles, The",
145
                  "disambiguation" : "",
146
                  "url" : "https://www.setlist.fm/setlists/the-beatles-23d6a88b.html"
147
               },
148
               "venue" : {
149
                  "id" : "33d62cf9",
150
                  "name" : "Hollywood Bowl",
151
                  "city" : {
152
                     "id" : "5368361",
153
                     "name" : "Los Angeles",
154
                     "state" : "California",
155
                     "stateCode" : "CA",
156
                     "coords" : {
157
                        "lat" : 34.052,
158
                        "long" : -118.244
159
                     },
160
                     "country" : {
161
                        "code" : "US",
162
                        "name" : "United States"
163
                     }
164
                  },
165
                  "url" : "https://www.setlist.fm/venue/hollywood-bowl-los-angeles-ca-usa-33d62cf9.html"
166
               },
167
               "tour" : {
168
                  "name" : "North American Tour 1964"
169
               },
170
               "set" : [ {
171
                  "song" : [ {
172
                     "name" : "Twist and Shout",
173
                     "cover" : {
174
                        "mbid" : "f18eac60-48d2-4d2b-b432-e43ce7e31d36",
175
                        "name" : "The Top Notes",
176
                        "sortName" : "Top Notes, The",
177
                        "url" : "https://www.setlist.fm/setlists/the-top-notes-53d433dd.html"
178
                     }
179
                  }, {
180
                     "name" : "You Can't Do That"
181
                  }, {
182
                     "name" : "All My Loving"
183
                  }, {
184
                     "name" : "She Loves You"
185
                  }, {
186
                     "name" : "Things We Said Today"
187
                  }, {
188
                     "name" : "Roll Over Beethoven",
189
                     "cover" : {
190
                        "mbid" : "592a3b6d-c42b-4567-99c9-ecf63bd66499",
191
                        "tmid" : 734540,
192
                        "name" : "Chuck Berry",
193
                        "sortName" : "Berry, Chuck",
194
                        "disambiguation" : "",
195
                        "url" : "https://www.setlist.fm/setlists/chuck-berry-63d6a2b7.html"
196
                     }
197
                  }, {
198
                     "name" : "Can't Buy Me Love"
199
                  }, {
200
                     "name" : "If I Fell"
201
                  }, {
202
                     "name" : "I Want to Hold Your Hand"
203
                  }, {
204
                     "name" : "Boys",
205
                     "cover" : {
206
                        "mbid" : "a8540ea0-1a74-4c22-8b70-1348a77a74a0",
207
                        "name" : "The Shirelles",
208
                        "sortName" : "Shirelles, The",
209
                        "disambiguation" : "",
210
                        "url" : "https://www.setlist.fm/setlists/the-shirelles-bd69d7a.html"
211
                     }
212
                  }, {
213
                     "name" : "A Hard Day's Night"
214
                  }, {
215
                     "name" : "Long Tall Sally",
216
                     "cover" : {
217
                        "mbid" : "95c2339b-8277-49a6-9aaf-08d8eeeaa0be",
218
                        "tmid" : 735520,
219
                        "name" : "Little Richard",
220
                        "sortName" : "Little Richard",
221
                        "disambiguation" : "",
222
                        "url" : "https://www.setlist.fm/setlists/little-richard-4bd6af2e.html"
223
                     }
224
                  } ]
225
               } ],
226
               "info" : "Recorded and published as 'The Beatles at the Hollywood Bowl'",
227
               "url" : "https://www.setlist.fm/setlist/the-beatles/1964/hollywood-bowl-los-angeles-ca-63de4613.html"
228
            }
229
EOD;
230
231
        $setlist = Setlist::fromApi(json_decode($data, true));
232
        static::assertSame('63de4613', $setlist->getId());
233
        static::assertSame('7be1aaa0', $setlist->getVersionId());
234
        static::assertNotNull($setlist->getVenue());
235
        static::assertNotNull($setlist->getArtist());
236
        static::assertEquals(new DateTime('23-08-1964'), $setlist->getEventDate(), '', 0);
237
        static::assertSame('Recorded and published as \'The Beatles at the Hollywood Bowl\'', $setlist->getInfo());
238
        static::assertCount(1, $setlist->getSets());
239
        static::assertNotNull($setlist->getTour());
240
        static::assertEquals(new DateTime('2013-10-20T05:18:08.000+0000'), $setlist->getUpdateDate(), '', 0);
241
        static::assertSame('https://www.setlist.fm/setlist/the-beatles/1964/hollywood-bowl-los-angeles-ca-63de4613.html', $setlist->getUrl());
242
    }
243
}
244