Code Duplication    Length = 138-138 lines in 2 locations

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

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

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

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