Skip to content

Commit 58966e5

Browse files
committed
Switch to PER 3.x coding standard
1 parent ad81fc9 commit 58966e5

File tree

11 files changed

+213
-196
lines changed

11 files changed

+213
-196
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ jobs:
2121
coverage: pcov
2222

2323
- run: composer install
24+
- run: composer lint
2425
- run: composer test
2526
- run: php vendor/bin/php-coveralls -v

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
2+
.php-cs-fixer.cache
23
.phpunit.cache
34
build
45
composer.lock

.php-cs-fixer.dist.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__ . DIRECTORY_SEPARATOR . 'src')
5+
->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests')
6+
->append(['.php-cs-fixer.dist.php']);
7+
8+
$rules = [
9+
'@PER-CS3x0' => true,
10+
];
11+
12+
return (new PhpCsFixer\Config())
13+
->setUsingCache(true)
14+
->setRules($rules)
15+
->setFinder($finder);

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
"ext-curl": "*"
1919
},
2020
"require-dev": {
21+
"friendsofphp/php-cs-fixer": "^3.89",
2122
"php-coveralls/php-coveralls": "^2.5",
2223
"php-mock/php-mock-phpunit": "^2.7",
23-
"phpunit/phpunit": "^12.0",
24-
"squizlabs/php_codesniffer": "^3.0"
24+
"phpunit/phpunit": "^12.0"
2525
},
2626
"autoload": {
2727
"psr-4": {
2828
"SpotifyWebAPI\\": "src/"
2929
}
3030
},
3131
"scripts": {
32-
"test": "phpcs src -v && phpunit"
32+
"lint": "php-cs-fixer fix -v --dry-run",
33+
"lint:fix": "php-cs-fixer fix -v",
34+
"test": "phpunit"
3335
}
3436
}

phpcs.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/Request.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ public function send(string $method, string $url, string|array|object $parameter
212212
];
213213

214214
switch ($method) {
215-
case 'DELETE': // No break
215+
// No break
216+
case 'DELETE':
216217
case 'PUT':
217218
$options[CURLOPT_CUSTOMREQUEST] = $method;
218219
$options[CURLOPT_POSTFIELDS] = $parameters;
@@ -297,9 +298,7 @@ protected function splitResponse(string $response): array
297298

298299
// Skip first set of headers for proxied requests etc.
299300
if (
300-
preg_match('/^HTTP\/1.\d 100 Continue/', $parts[0]) ||
301-
preg_match('/^HTTP\/1.\d 200 Connection established/', $parts[0]) ||
302-
preg_match('/^HTTP\/1.\d 200 Tunnel established/', $parts[0])
301+
preg_match('/^HTTP\/1.\d [100 Continue|200 Connection established|200 Tunnel established]/', $parts[0])
303302
) {
304303
return [
305304
$parts[1],

src/Session.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(
2828
string $clientId,
2929
string $clientSecret = '',
3030
string $redirectUri = '',
31-
?Request $request = null
31+
?Request $request = null,
3232
) {
3333
$this->setClientId($clientId);
3434
$this->setClientSecret($clientSecret);
@@ -78,7 +78,7 @@ public function generateState(int $length = 16): string
7878
{
7979
// Length will be doubled when converting to hex
8080
return bin2hex(
81-
random_bytes($length / 2)
81+
random_bytes($length / 2),
8282
);
8383
}
8484

src/SpotifyWebAPI.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function sendRequest(
111111
string $method,
112112
string $uri,
113113
string|array $parameters = [],
114-
array $headers = []
114+
array $headers = [],
115115
): array {
116116
$this->request->setOptions([
117117
'default_headers' => $this->options['default_headers'],
@@ -312,10 +312,10 @@ public function addMyTracks(array|object $tracks): bool
312312
public function addPlaylistTracks(
313313
string $playlistId,
314314
string|array $tracks,
315-
array|object $options = []
315+
array|object $options = [],
316316
): string|bool {
317317
$options = array_merge((array) $options, [
318-
'uris' => (array) $this->idToUri($tracks, 'track')
318+
'uris' => (array) $this->idToUri($tracks, 'track'),
319319
]);
320320

321321
$options = json_encode($options);

tests/RequestTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace SpotifyWebAPI;
66

7-
use \phpmock\phpunit\PHPMock;
8-
use \PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
9-
use \PHPUnit\Framework\TestCase;
7+
use phpmock\phpunit\PHPMock;
8+
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
9+
use PHPUnit\Framework\TestCase;
1010

1111
#[RunTestsInSeparateProcesses]
1212
class RequestTest extends TestCase
@@ -75,7 +75,7 @@ public function testAccountMalformed()
7575
$this->setupFunctionMock('curl_getinfo')->willReturn(400);
7676

7777
$parameters = [
78-
'grant_type' => 'client_credentials'
78+
'grant_type' => 'client_credentials',
7979
];
8080

8181
$headers = [
@@ -176,7 +176,7 @@ public function testSendDelete()
176176
function (\CurlHandle $ch, array $options) {
177177
$this->assertEquals('DELETE', $options[CURLOPT_CUSTOMREQUEST]);
178178
$this->assertEquals('foo=bar', $options[CURLOPT_POSTFIELDS]);
179-
}
179+
},
180180
);
181181

182182
$parameters = [
@@ -194,7 +194,7 @@ public function testSendPost()
194194
function (\CurlHandle $ch, array $options) {
195195
$this->assertEquals(true, $options[CURLOPT_POST]);
196196
$this->assertEquals('foo=bar', $options[CURLOPT_POSTFIELDS]);
197-
}
197+
},
198198
);
199199

200200
$parameters = [
@@ -212,7 +212,7 @@ public function testSendPut()
212212
function (\CurlHandle $ch, array $options) {
213213
$this->assertEquals('PUT', $options[CURLOPT_CUSTOMREQUEST]);
214214
$this->assertEquals('foo=bar', $options[CURLOPT_POSTFIELDS]);
215-
}
215+
},
216216
);
217217

218218
$parameters = [
@@ -230,7 +230,7 @@ public function testSendGetParameters()
230230
function (\CurlHandle $ch, array $options) {
231231
$this->assertEquals('GET', $options[CURLOPT_CUSTOMREQUEST]);
232232
$this->assertEquals('https://www.example.com/?foo=bar', $options[CURLOPT_URL]);
233-
}
233+
},
234234
);
235235

236236
$parameters = [
@@ -265,7 +265,7 @@ public function testSendStatus()
265265
public function testSendTransportError()
266266
{
267267
$this->expectExceptionObject(
268-
new SpotifyWebAPIException('cURL transport error: 6 Could not resolve host: non-existent')
268+
new SpotifyWebAPIException('cURL transport error: 6 Could not resolve host: non-existent'),
269269
);
270270

271271
$request = new Request();
@@ -303,7 +303,7 @@ public function testSendUnknownError()
303303
$this->setupFunctionMock('curl_getinfo')->willReturn(400);
304304

305305
$this->expectExceptionObject(
306-
new SpotifyWebAPIException('An unknown error occurred.', 400)
306+
new SpotifyWebAPIException('An unknown error occurred.', 400),
307307
);
308308

309309
$request = new Request();
@@ -316,7 +316,7 @@ public function testSendUnknownErrorBodyFallback()
316316
$this->setupFunctionMock('curl_getinfo')->willReturn(400);
317317

318318
$this->expectExceptionObject(
319-
new SpotifyWebAPIException('Foobar error', 400)
319+
new SpotifyWebAPIException('Foobar error', 400),
320320
);
321321

322322
$request = new Request();

tests/SessionTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SpotifyWebAPI;
66

7-
use \PHPUnit\Framework\TestCase;
7+
use PHPUnit\Framework\TestCase;
88

99
class SessionTest extends TestCase
1010
{
@@ -19,7 +19,7 @@ private function setupRequestMock(
1919
string $expectedUri,
2020
string|array $expectedParameters,
2121
array $expectedHeaders,
22-
array $expectedReturn
22+
array $expectedReturn,
2323
) {
2424
$requestMock = $this->createMock(Request::class);
2525

@@ -29,7 +29,7 @@ private function setupRequestMock(
2929
$this->equalTo($expectedMethod),
3030
$this->equalTo($expectedUri),
3131
$this->equalTo($expectedParameters),
32-
$this->equalTo($expectedHeaders)
32+
$this->equalTo($expectedHeaders),
3333
)
3434
->willReturn($expectedReturn);
3535

@@ -140,7 +140,7 @@ public function testRefreshAccessToken()
140140
'/api/token',
141141
$expected,
142142
$headers,
143-
$return
143+
$return,
144144
);
145145

146146
$session = new Session($this->clientID, $this->clientSecret, $this->redirectURI, $requestMock);
@@ -168,7 +168,7 @@ public function testRefreshAccessTokenNoClientSecret()
168168
'/api/token',
169169
$expected,
170170
[],
171-
$return
171+
$return,
172172
);
173173

174174
$session = new Session($this->clientID, '', $this->redirectURI, $requestMock);
@@ -200,7 +200,7 @@ public function testRefreshAccessTokenExistingToken()
200200
'/api/token',
201201
$expected,
202202
$headers,
203-
$return
203+
$return,
204204
);
205205

206206
$session = new Session($this->clientID, $this->clientSecret, $this->redirectURI, $requestMock);
@@ -234,7 +234,7 @@ public function testRefreshAccessTokenNoReturnedToken()
234234
'/api/token',
235235
$expected,
236236
$headers,
237-
$return
237+
$return,
238238
);
239239

240240
$session = new Session($this->clientID, $this->clientSecret, $this->redirectURI, $requestMock);
@@ -264,7 +264,7 @@ public function testRefreshAccessTokenNoPreviousToken()
264264
'/api/token',
265265
$expected,
266266
$headers,
267-
$return
267+
$return,
268268
);
269269

270270
$session = new Session($this->clientID, $this->clientSecret, $this->redirectURI, $requestMock);
@@ -293,7 +293,7 @@ public function testRequestAccessToken()
293293
'/api/token',
294294
$expected,
295295
[],
296-
$return
296+
$return,
297297
);
298298

299299
$session = new Session($this->clientID, $this->clientSecret, $this->redirectURI, $requestMock);
@@ -327,7 +327,7 @@ public function testRequestAccessTokenPkce()
327327
'/api/token',
328328
$expected,
329329
[],
330-
$return
330+
$return,
331331
);
332332

333333
$session = new Session($this->clientID, '', $this->redirectURI, $requestMock);
@@ -359,7 +359,7 @@ public function testRequestCredentialsToken()
359359
'/api/token',
360360
$expected,
361361
$headers,
362-
$return
362+
$return,
363363
);
364364

365365
$session = new Session($this->clientID, $this->clientSecret, $this->redirectURI, $requestMock);

0 commit comments

Comments
 (0)