Passed
Push — feature/code-quality ( b3f671...a899ee )
by Oguzhan
05:01 queued 02:25
created

Track::transformSingle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: oguzu
5
 * Date: 29-3-2017
6
 * Time: 16:29
7
 */
8
9
namespace Pbxg33k\MusicInfo\Service\VocaDB\Endpoint;
10
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Pbxg33k\MusicInfo\Model\BaseModel;
13
use Pbxg33k\MusicInfo\Model\IMusicServiceEndpoint;
14
use Pbxg33k\VocaDB\Song as TrackEndpoint;
15
use Pbxg33k\VocaDB\Models\Track as VocaDBTrackModel;
16
use Pbxg33k\MusicInfo\Model\Track as TrackModel;
17
18
class Track extends TrackEndpoint implements IMusicServiceEndpoint
19
{
20
    const DATA_SOURCE = 'vocadb';
21
22
    protected $parent;
23
24
    /**
25
     * @param $apiService
26
     *
27
     * @return Track
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 VocaDBTrackModel $raw
40
     *
41
     * @return BaseModel
42
     */
43
    public function transformSingle($raw)
44
    {
45
        $object = new TrackModel();
46
        $object
47
            ->setId($raw->getId())
48
            ->setName($raw->getName())
49
            ->setDataSource(self::DATA_SOURCE)
50
            ->setRawData($raw);
51
52
        return $object;
53
54
    }
55
56
    /**
57
     * Transform collection to models
58
     *
59
     * @param $raw
60
     *
61
     * @return ArrayCollection
62
     */
63
    public function transformCollection($raw)
64
    {
65
        $collection = new ArrayCollection();
66
        foreach ($raw->collection as $artist) {
67
            $collection->add($this->transformSingle($artist));
68
        }
69
70
        return $collection;
71
    }
72
73
    /**
74
     * Transform to models
75
     *
76
     * @param $raw
77
     *
78
     * @return ArrayCollection
79
     */
80
    public function transform($raw)
81
    {
82
        return $this->transformCollection($raw);
83
    }
84
85
    /**
86
     * @return mixed
87
     */
88
    public function getParent()
89
    {
90
        return $this->parent;
91
    }
92
93
    /**
94
     * @param $guid
95
     *
96
     * @return ArrayCollection
97
     */
98
    public function getByGuid($guid, $complete = true)
99
    {
100
        return $this->transform(parent::getById($guid, $complete));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getById() instead of getByGuid()). Are you sure this is correct? If so, you might want to change this to $this->getById().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
101
    }
102
103
    public function getByName($name, $complete = true)
104
    {
105
        return $this->transform(parent::getByName($name, $complete));
106
    }
107
}
108