Passed
Push — feature/cache ( 84566e )
by Oguzhan
04:37
created

Track::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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
use Pbxg33k\VocaDB\Client;
18
use Psr\Cache\CacheItemPoolInterface;
19
20
class Track extends TrackEndpoint implements IMusicServiceEndpoint
21
{
22
    const DATA_SOURCE = 'vocadb';
23
24
    /**
25
     * @var CacheItemPoolInterface
26
     */
27
    protected $cache;
28
29
    protected $parent;
30
31 39
    public function __construct(Client $client, CacheItemPoolInterface $cache)
32
    {
33 39
        $this->setCache($cache);
34 39
        parent::__construct($client);
35 39
    }
36
37
    /**
38
     * @param CacheItemPoolInterface $cacheItemPool
39
     * @return $this
40
     */
41 39
    public function setCache(CacheItemPoolInterface $cacheItemPool)
42
    {
43 39
        $this->cache = $cacheItemPool;
44
45 39
        return $this;
46
    }
47
48
    /**
49
     * @param $apiService
50
     *
51
     * @return Track
52
     */
53
    public function setParent($apiService)
54
    {
55
        $this->parent = $apiService;
56
57
        return $this;
58
    }
59
60
    /**
61
     * Transform single item to model
62
     *
63
     * @param VocaDBTrackModel $raw
64
     *
65
     * @return BaseModel
66
     */
67
    public function transformSingle($raw)
68
    {
69
        $object = new TrackModel();
70
        $object
71
            ->setId($raw->getId())
72
            ->setName($raw->getName());
73
74
        var_dump(
0 ignored issues
show
Security Debugging Code introduced by
var_dump(__FILE__, __LINE__, $raw); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
75
            __FILE__, __LINE__,
76
            $raw
77
        ); die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method transformSingle() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
78
79
        return $object;
0 ignored issues
show
Unused Code introduced by
return $object; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
80
81
    }
82
83
    /**
84
     * Transform collection to models
85
     *
86
     * @param $raw
87
     *
88
     * @return ArrayCollection
89
     */
90
    public function transformCollection($raw)
91
    {
92
        $collection = new ArrayCollection();
93
        foreach ($raw->collection as $artist) {
94
            $collection->add($this->transformSingle($artist));
95
        }
96
97
        return $collection;
98
    }
99
100
    /**
101
     * Transform to models
102
     *
103
     * @param $raw
104
     *
105
     * @return ArrayCollection
106
     */
107
    public function transform($raw)
108
    {
109
        return $this->transformCollection($raw);
110
    }
111
112
    /**
113
     * @return mixed
114
     */
115
    public function getParent()
116
    {
117
        return $this->parent;
118
    }
119
120
    /**
121
     * @param $guid
122
     *
123
     * @return ArrayCollection
124
     */
125
    public function getByGuid($guid, $complete = true)
126
    {
127
        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...
128
    }
129
130
    public function getByName($name, $complete = true)
131
    {
132
        return $this->transform(parent::getByName($name, $complete));
133
    }
134
}
135