Passed
Push — main ( 9a7c47...4b510f )
by Daniel
03:39
created

SongListItem::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 18
ccs 14
cts 14
cp 1
crap 1
rs 9.7998
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Lib;
6
7
use Uxmp\Core\Component\Config\ConfigProviderInterface;
8
use Uxmp\Core\Orm\Model\AlbumInterface;
9
use Uxmp\Core\Orm\Model\SongInterface;
10
11
final class SongListItem implements SongListItemInterface
12
{
13 2
    public function __construct(
14
        private ConfigProviderInterface $config,
15
        private SongInterface $song,
16
        private AlbumInterface $album
17
    ) {
18 2
    }
19
20 1
    public function jsonSerialize()
21
    {
22 1
        $songId = $this->song->getId();
23 1
        $baseUrl = $this->config->getBaseUrl();
24
25 1
        $artist = $this->album->getArtist();
26
27
        return [
28 1
            'id' => $songId,
29 1
            'name' => $this->song->getTitle(),
30 1
            'artistName' => $artist->getTitle(),
31 1
            'albumName' => $this->album->getTitle(),
32 1
            'trackNumber' => $this->song->getTrackNumber(),
33 1
            'playUrl' => sprintf('%s/play/%d', $baseUrl, $songId),
34 1
            'cover' => sprintf('%s/art/album/%s', $baseUrl, $this->album->getMbid()),
35 1
            'artistId' => $artist->getId(),
36 1
            'albumId' => $this->album->getId(),
37 1
            'length' => $this->song->getLength(),
38
        ];
39
    }
40
}
41