Test Failed
Pull Request — develop (#22)
by Oguzhan
03:49
created

Artist::transformSingle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
namespace Pbxg33k\MusicInfo\Service\MusicBrainz\Endpoint;
3
4
use Doctrine\Common\Collections\ArrayCollection;
5
use MusicBrainz\Filters\ArtistFilter;
6
use Pbxg33k\MusicInfo\Model\Artist as ArtistModel;
7
use Pbxg33k\MusicInfo\Model\IMusicServiceEndpoint;
8
use Pbxg33k\MusicInfo\Service\MusicBrainz\Service;
9
10
class Artist implements IMusicServiceEndpoint
11
{
12
    const DATA_SOURCE = 'musicbrainz';
13
    /**
14
     * @var Service
15
     */
16
    protected $parent;
17
18
    public function __construct($parent)
19
    {
20
        $this->setParent($parent);
21
    }
22
23
    /**
24
     * @param $apiService
25
     *
26
     * @return mixed
27
     */
28
    public function setParent($apiService)
29
    {
30
        $this->parent = $apiService;
31
    }
32
33
    /**
34
     * @param $raw
35
     *
36
     * @return ArtistModel
37
     */
38
    public function transformSingle($raw)
39
    {
40
        $object = new ArtistModel;
41
        $object
42
            ->setId($raw->id)
43
            ->setName($raw->name)
44
            ->setType('artist')
45
            ->setRawData($raw)
46
            ->setDataSource(self::DATA_SOURCE);
47
48
        return $object;
49
    }
50
51
    /**
52
     * @param $raw
53
     *
54
     * @return ArrayCollection
55
     * @throws \Exception
56
     */
57
    public function transformCollection($raw)
58
    {
59
        $collection = new ArrayCollection();
60
        if(is_array($raw)) {
61
            foreach ($raw as $artist) {
62
                $collection->add($this->transformSingle($artist));
63
            }
64
        }
65
66
        return $collection;
67
    }
68
69
    /**
70
     * @param $raw
71
     *
72
     * @return ArrayCollection
73
     * @throws \Exception
74
     */
75
    public function transform($raw)
76
    {
77
        return $this->transformCollection($raw);
78
    }
79
80
    /**
81
     * @return mixed
82
     */
83
    public function getParent()
84
    {
85
        return $this->parent;
86
    }
87
88
    /**
89
     * @param $arguments
90
     *
91
     * @return mixed
92
     */
93
    public function get($arguments)
94
    {
95
        // TODO: Implement get() method.
96
    }
97
98
    /**
99
     * @param $arguments
100
     *
101
     * @return mixed
102
     */
103
    public function getComplete($arguments)
104
    {
105
        // TODO: Implement getComplete() method.
106
    }
107
108
    /**
109
     * @param $id
110
     *
111
     * @return mixed
112
     */
113
    public function getById($id)
114
    {
115
        // TODO: Implement getById() method.
116
    }
117
118
    /**
119
     * @param $name
120
     *
121
     * @return mixed
122
     */
123
    public function getByName($name)
124
    {
125
        return $this->transform($this->parent->getApiClient()->search(new ArtistFilter(['artist' => $name])));
126
    }
127
128
    /**
129
     * @param $guid
130
     *
131
     * @return mixed
132
     */
133
    public function getByGuid($guid)
134
    {
135
        // TODO: Implement getByGuid() method.
136
    }
137
}