Skip to content

Commit 776d063

Browse files
committed
Add null return type to SpotifyWebAPI::getMyCurrentTrack() and SpotifyWebAPI::getMyCurrentPlaybackInfo()
Closes #269
1 parent c115c3c commit 776d063

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/SpotifyWebAPI.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -1133,9 +1133,10 @@ public function getMultipleAudioFeatures(string|array $trackIds): array|object
11331133
* - string market Optional. ISO 3166-1 alpha-2 country code, provide this if you wish to apply Track Relinking.
11341134
* - string|array additional_types Optional. Types of media to return info about.
11351135
*
1136-
* @return array|object The user's currently playing track. Type is controlled by the `return_assoc` option.
1136+
* @return array|object|null The user's currently playing track or null if nothing's currently playing.
1137+
* Type is controlled by the `return_assoc` option.
11371138
*/
1138-
public function getMyCurrentTrack(array|object $options = []): array|object
1139+
public function getMyCurrentTrack(array|object $options = []): array|object|null
11391140
{
11401141
$uri = '/v1/me/player/currently-playing';
11411142
$options = (array) $options;
@@ -1172,9 +1173,10 @@ public function getMyDevices(): array|object
11721173
* - string market Optional. ISO 3166-1 alpha-2 country code, provide this if you wish to apply Track Relinking.
11731174
* - string|array additional_types Optional. Types of media to return info about.
11741175
*
1175-
* @return array|object The user's playback information. Type is controlled by the `return_assoc` option.
1176+
* @return array|object|null The user's playback information or null if nothing's currently playing.
1177+
* Type is controlled by the `return_assoc` option.
11761178
*/
1177-
public function getMyCurrentPlaybackInfo(array|object $options = []): array|object
1179+
public function getMyCurrentPlaybackInfo(array|object $options = []): array|object|null
11781180
{
11791181
$uri = '/v1/me/player';
11801182
$options = (array) $options;

tests/SpotifyWebAPITest.php

+32
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,22 @@ public function testGetMyCurrentTrack()
12661266
$this->assertObjectHasProperty('item', $response);
12671267
}
12681268

1269+
public function testGetMyCurrentTrackEmptyResponse()
1270+
{
1271+
$return = ['body' => null];
1272+
$api = $this->setupApi(
1273+
'GET',
1274+
'/v1/me/player/currently-playing',
1275+
[],
1276+
[],
1277+
$return
1278+
);
1279+
1280+
$response = $api->getMyCurrentTrack([]);
1281+
1282+
$this->assertNull($response);
1283+
}
1284+
12691285
public function testGetMyDevices()
12701286
{
12711287
$return = ['body' => get_fixture('user-devices')];
@@ -1308,6 +1324,22 @@ public function testGetMyCurrentPlaybackInfo()
13081324
$this->assertObjectHasProperty('item', $response);
13091325
}
13101326

1327+
public function testGetMyCurrentPlaybackInfoEmptyResponse()
1328+
{
1329+
$return = ['body' => null];
1330+
$api = $this->setupApi(
1331+
'GET',
1332+
'/v1/me/player',
1333+
[],
1334+
[],
1335+
$return
1336+
);
1337+
1338+
$response = $api->getMyCurrentPlaybackInfo([]);
1339+
1340+
$this->assertNull($response);
1341+
}
1342+
13111343
public function testGetMyPlaylists()
13121344
{
13131345
$options = ['limit' => 10];

0 commit comments

Comments
 (0)