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

Album::transformCollection()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
ccs 0
cts 8
cp 0
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
crap 12
1
<?php
2
/*******************************************************************************
3
 * This file is part of the Pbxg33k\MusicInfo package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * (c) 2017 Oguzhan uysal. All rights reserved
9
 ******************************************************************************/
10
11
/**
12
 * Created by PhpStorm.
13
 * User: PBX_g33k
14
 * Date: 22-May-16
15
 * Time: 22:21
16
 */
17
18
namespace Pbxg33k\MusicInfo\Service\VocaDB\Endpoint;
19
20
use Doctrine\Common\Collections\ArrayCollection;
21
use Pbxg33k\MusicInfo\Model\Artist as ArtistModel;
22
use Pbxg33k\MusicInfo\Model\IMusicServiceEndpoint;
23
use Pbxg33k\VocaDB\Album as AlbumEndpoint;
24
use Pbxg33k\MusicInfo\Model\Album as AlbumModel;
25
use Pbxg33k\VocaDB\Models\Collections\AlbumCollection;
26
use Pbxg33k\VocaDB\Models\Album as VocaDBModel;
27
28
class Album extends AlbumEndpoint implements IMusicServiceEndpoint
29
{
30
    /**
31
     * @return mixed
32
     */
33
    public function getParent()
34
    {
35
        // TODO: Implement getApiService() method.
36
    }
37
38
    /**
39
     * Aliases getById
40
     *
41
     * @param $guid
42
     *
43
     * @return mixed
44
     */
45
    public function getByGuid($guid)
46
    {
47
        return $this->getById($guid);
48
    }
49
50
    /**
51
     * @return mixed
52
     */
53
    public function setParent($apiService)
54
    {
55
        // TODO: Implement setApiService() method.
56
    }
57
58
    /**
59
     * @param VocaDBModel $raw
60
     * @return AlbumModel
61
     */
62
    public function transformSingle($raw)
63
    {
64
        $object = new AlbumModel();
65
        $object
66
            ->setId($raw->getId())
67
            ->setName($raw->getName())
68
            ->setArtists(
69
                new ArrayCollection(
70
                    [
71
                    (new ArtistModel())->setName($raw->getName())
72
                    ]
73
                )
74
            )
75
            ->setType($raw->getDiscType())
76
            ->setImage($raw->getMainPicture()->urlThumb)
77
            ->setReleaseDate(new \DateTime($raw->getReleaseDate()->formatted))
78
            ->setDataSource('vocadb')
79
            ->setRawData($raw);
80
81
        return $object;
82
    }
83
84
    public function transformCollection($raw)
85
    {
86
        $collection = new ArrayCollection();
87
        if ($raw instanceof AlbumCollection) {
88
            foreach ($raw->collection as $album) {
89
                $collection->add($this->transformSingle($album));
90
            }
91
92
            return $collection;
93
        }
94
95
        throw new \Exception('Transform failed. Object is not an instance of AlbumCollection');
96
    }
97
98
    public function transform($raw)
99
    {
100
        return $this->transformCollection($raw);
101
    }
102
103
    public function getByName($name, $complete = true)
104
    {
105
        return $this->transform(parent::getByName($name, $complete));
106
    }
107
}
108