Code Duplication    Length = 138-143 lines in 2 locations

src/Service/Spotify/Endpoint/Album.php 1 location

@@ 20-162 (lines=143) @@
17
use Pbxg33k\MusicInfo\Service\Spotify\Service as SpotifyService;
18
use Pbxg33k\MusicInfo\Model\Album as AlbumModel;
19
20
class Album implements IMusicServiceEndpoint
21
{
22
    const DATA_SOURCE = 'spotify';
23
24
    /**
25
     * @var SpotifyService
26
     */
27
    protected $parent;
28
29
    public function __construct(SpotifyService $service)
30
    {
31
        $this->parent = $service;
32
    }
33
34
    /**
35
     * @param $apiService
36
     *
37
     * @return mixed
38
     */
39
    public function setParent($apiService)
40
    {
41
        $this->parent = $apiService;
42
43
        return $this;
44
    }
45
46
    /**
47
     * Transform single item to model
48
     *
49
     * @param $raw
50
     *
51
     * @return BaseModel
52
     */
53
    public function transformSingle($raw)
54
    {
55
        $object = new AlbumModel();
56
        $object
57
            ->setId($raw->id)
58
            ->setName($raw->name)
59
            ->setType($raw->album_type)
60
            ->setUri($raw->external_urls->spotify)
61
            ->setRawData($raw)
62
            ->setDataSource(self::DATA_SOURCE);
63
64
        return $object;
65
    }
66
67
    /**
68
     * @param $raw
69
     *
70
     * @return ArrayCollection
71
     * @throws \Exception
72
     */
73
    public function transformCollection($raw)
74
    {
75
        $collection = new ArrayCollection();
76
        if (is_object($raw) && isset($raw->albums)) {
77
            foreach ($raw->albums->items as $album) {
78
                $collection->add($this->transformSingle($album));
79
            }
80
81
            return $collection;
82
        }
83
84
        throw new \Exception('Transform failed');
85
    }
86
87
    /**
88
     * Transform to models
89
     *
90
     * @param $raw
91
     *
92
     * @return ArrayCollection
93
     */
94
    public function transform($raw)
95
    {
96
        return $this->transformCollection($raw);
97
    }
98
99
    /**
100
     * @return mixed
101
     */
102
    public function getParent()
103
    {
104
        return $this->parent;
105
    }
106
107
    /**
108
     * @param $arguments
109
     *
110
     * @return void
111
     *
112
     * @throws MethodNotImplementedException
113
     */
114
    public function get($arguments)
115
    {
116
        throw new MethodNotImplementedException();
117
        // TODO: Implement get() method.
118
    }
119
120
    /**
121
     * @param $arguments
122
     *
123
     * @return void
124
     *
125
     * @throws MethodNotImplementedException
126
     */
127
    public function getComplete($arguments)
128
    {
129
        throw new MethodNotImplementedException();
130
        // TODO: Implement getComplete() method.
131
    }
132
133
    /**
134
     * @param $id
135
     *
136
     * @return array|object
137
     */
138
    public function getById($id)
139
    {
140
        return $this->getByGuid($id);
141
    }
142
143
    /**
144
     * @param $name
145
     *
146
     * @return mixed
147
     */
148
    public function getByName($name)
149
    {
150
        return $this->transform($this->getParent()->getApiClient()->search($name, 'album'));
151
    }
152
153
    /**
154
     * @param $guid
155
     *
156
     * @return array|object
157
     */
158
    public function getByGuid($guid)
159
    {
160
        return $this->getParent()->getApiClient()->getAlbum($guid);
161
    }
162
}

src/Service/Spotify/Endpoint/Artist.php 1 location

@@ 19-156 (lines=138) @@
16
use Pbxg33k\MusicInfo\Model\IMusicServiceEndpoint;
17
use Pbxg33k\MusicInfo\Service\Spotify\Service as SpotifyService;
18
19
class Artist implements IMusicServiceEndpoint
20
{
21
    const DATA_SOURCE = 'spotify';
22
    /**
23
     * @var SpotifyService
24
     */
25
    protected $parent;
26
27
    public function __construct(SpotifyService $apiService)
28
    {
29
        $this->parent = $apiService;
30
    }
31
32
    /**
33
     * @param $parent
34
     *
35
     * @return $this
36
     */
37
    public function setParent($parent)
38
    {
39
        $this->parent = $parent;
40
41
        return $this;
42
    }
43
44
    /**
45
     * @return SpotifyService
46
     */
47
    public function getParent()
48
    {
49
        return $this->parent;
50
    }
51
52
    /**
53
     * @param $arguments
54
     *
55
     * @return void
56
     *
57
     * @throws MethodNotImplementedException
58
     */
59
    public function get($arguments)
60
    {
61
        throw new MethodNotImplementedException;
62
        // TODO: Implement get() method.
63
    }
64
65
    /**
66
     * @param $arguments
67
     *
68
     * @return void
69
     *
70
     * @throws MethodNotImplementedException
71
     */
72
    public function getComplete($arguments)
73
    {
74
        throw new MethodNotImplementedException;
75
        // TODO: Implement getComplete() method.
76
    }
77
78
    /**
79
     * @param $id
80
     *
81
     * @return mixed
82
     */
83
    public function getById($id)
84
    {
85
        return $this->getById($id);
86
    }
87
88
    /**
89
     * @param $name
90
     *
91
     * @return mixed
92
     */
93
    public function getByName($name)
94
    {
95
        return $this->transform($this->getParent()->getApiClient()->search($name, 'artist'));
96
    }
97
98
    /**
99
     * @param $guid
100
     *
101
     * @return mixed
102
     */
103
    public function getByGuid($guid)
104
    {
105
        return $this->getParent()->getApiClient()->getArtist($guid);
106
    }
107
108
    /**
109
     * @param $raw
110
     *
111
     * @return ArtistModel
112
     */
113
    public function transformSingle($raw)
114
    {
115
        $object = new ArtistModel;
116
        $object
117
            ->setId($raw->id)
118
            ->setName($raw->name)
119
            ->setType($raw->type)
120
            ->setUri($raw->external_urls->spotify)
121
            ->setRawData($raw)
122
            ->setDataSource(self::DATA_SOURCE);
123
124
        return $object;
125
    }
126
127
    /**
128
     * @param $raw
129
     *
130
     * @return ArrayCollection
131
     * @throws \Exception
132
     */
133
    public function transformCollection($raw)
134
    {
135
        $collection = new ArrayCollection();
136
        if (is_object($raw) && isset($raw->artists)) {
137
            foreach ($raw->artists->items as $artist) {
138
                $collection->add($this->transformSingle($artist));
139
            }
140
141
            return $collection;
142
        }
143
        throw new \Exception('Transform failed');
144
    }
145
146
    /**
147
     * @param $raw
148
     *
149
     * @return ArrayCollection
150
     * @throws \Exception
151
     */
152
    public function transform($raw)
153
    {
154
        return $this->transformCollection($raw);
155
    }
156
}