Completed
Push — feature/spotify ( 7a052d...23e210 )
by Oguzhan
02:13
created

Album   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 137
rs 10

11 Methods

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