Passed
Pull Request — master (#1)
by Rafal
07:10
created

SpotifyWebApi::getUserPlaylist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 3
1
<?php declare(strict_types=1);
2
3
4
namespace SpotifyApiConnect\Application\SpotifyWebApiPhp;
5
6
use SpotifyApiConnect\Domain\DataTransferObject\PlaylistDataProvider;
7
use SpotifyApiConnect\Domain\DataTransferObject\PlaylistTracksDataProvider;
8
use SpotifyWebAPI\SpotifyWebAPI as BaseSpotifyWebAPI;
9
use SpotifyWebAPI\Request;
10
use SpotifyWebAPI\SpotifyWebAPIException;
11
12
class SpotifyWebApi implements SpotifyWebApiInterface
13
{
14
    /**
15
     * @var BaseSpotifyWebAPI
16
     */
17
    private $baseSpotifyWebAPI;
18
19
    public function __construct()
20
    {
21
        $this->baseSpotifyWebAPI = new BaseSpotifyWebAPI();
22
    }
23
24
    /**
25
     * @param string $userId
26
     * @param string $playlistId
27
     * @param array $tracks
28
     * @param array $options
29
     * @return bool
30
     */
31
    public function addUserPlaylistTracks(string $userId, string $playlistId, array $tracks, array $options = [])
32
    {
33
        return $this->baseSpotifyWebAPI->addUserPlaylistTracks($userId, $playlistId, $tracks, $options);
0 ignored issues
show
Deprecated Code introduced by
The function SpotifyWebAPI\SpotifyWeb...addUserPlaylistTracks() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

33
        return /** @scrutinizer ignore-deprecated */ $this->baseSpotifyWebAPI->addUserPlaylistTracks($userId, $playlistId, $tracks, $options);
Loading history...
34
    }
35
36
    /**
37
     * @param string $userId
38
     * @param string $playlistId
39
     * @param array $tracks
40
     * @param string $snapshotId
41
     * @return bool|string
42
     */
43
    public function deleteUserPlaylistTracks(string $userId, string $playlistId, array $tracks, string $snapshotId = '')
44
    {
45
        return $this->baseSpotifyWebAPI->deleteUserPlaylistTracks($userId, $playlistId, $tracks, $snapshotId);
0 ignored issues
show
Deprecated Code introduced by
The function SpotifyWebAPI\SpotifyWeb...eteUserPlaylistTracks() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

45
        return /** @scrutinizer ignore-deprecated */ $this->baseSpotifyWebAPI->deleteUserPlaylistTracks($userId, $playlistId, $tracks, $snapshotId);
Loading history...
46
    }
47
48
    /**
49
     * @param string $playlistId
50
     * @param array $options
51
     * @return PlaylistDataProvider
52
     */
53
    public function getPlaylist(string $playlistId, array $options = []): PlaylistDataProvider
54
    {
55
        $this->baseSpotifyWebAPI->setReturnType(Request::RETURN_ASSOC);
56
        $jsonObjectResult = $this->baseSpotifyWebAPI->getPlaylist($playlistId, $options);
57
        $this->baseSpotifyWebAPI->setReturnType(Request::RETURN_OBJECT);
58
59
        $playlistDataProvider = new PlaylistDataProvider();
60
        $playlistDataProvider->fromArray($jsonObjectResult);
0 ignored issues
show
Bug introduced by
It seems like $jsonObjectResult can also be of type object; however, parameter $data of Xervice\DataProvider\Bus...taProvider::fromArray() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
        $playlistDataProvider->fromArray(/** @scrutinizer ignore-type */ $jsonObjectResult);
Loading history...
61
62
        return $playlistDataProvider;
63
64
    }
65
66
    /**
67
     * @param string $userId
68
     * @param array $options
69
     * @return array|object
70
     */
71
    public function getUserPlaylists(string $userId, array $options = [])
72
    {
73
        return $this->baseSpotifyWebAPI->getUserPlaylists($userId, $options);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->baseSpotif...ists($userId, $options) also could return the type array which is incompatible with the return type mandated by SpotifyApiConnect\Applic...ace::getUserPlaylists() of object.
Loading history...
74
    }
75
76
    /**
77
     * @param string $playlistId
78
     * @param array $options
79
     * @return PlaylistTracksDataProvider
80
     */
81
    public function getPlaylistTracks(string $playlistId, array $options = []) : PlaylistTracksDataProvider
82
    {
83
        $this->baseSpotifyWebAPI->setReturnType(Request::RETURN_ASSOC);
84
        $jsonObjectResult = $this->baseSpotifyWebAPI->getPlaylistTracks($playlistId, $options);
85
        $this->baseSpotifyWebAPI->setReturnType(Request::RETURN_OBJECT);
86
87
        $playlistTracksDataProvider = new PlaylistTracksDataProvider();
88
        $playlistTracksDataProvider->fromArray($jsonObjectResult);
0 ignored issues
show
Bug introduced by
It seems like $jsonObjectResult can also be of type object; however, parameter $data of Xervice\DataProvider\Bus...taProvider::fromArray() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

88
        $playlistTracksDataProvider->fromArray(/** @scrutinizer ignore-type */ $jsonObjectResult);
Loading history...
89
90
        return $playlistTracksDataProvider;
91
    }
92
93
    /**
94
     * @param string $query
95
     * @param array $type
96
     * @param array $options
97
     * @return array|object
98
     */
99
    public function search(string $query, array $type, array $options = [])
100
    {
101
        return $this->baseSpotifyWebAPI->search($query, $type, $options);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->baseSpotif...query, $type, $options) also could return the type array which is incompatible with the return type mandated by SpotifyApiConnect\Applic...bApiInterface::search() of object.
Loading history...
102
    }
103
104
    /**
105
     * @param string $accessToken
106
     */
107
    public function setAccessToken(string $accessToken)
108
    {
109
        $this->baseSpotifyWebAPI->setAccessToken($accessToken);
110
    }
111
112
}