Passed
Push — main ( cb2c48...010f0d )
by Daniel
05:13
created

AlbumListItem::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 1
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Lib;
6
7
use JsonSerializable;
8
use Uxmp\Core\Component\Config\ConfigProviderInterface;
9
use Uxmp\Core\Orm\Model\AlbumInterface;
10
11
/**
12
 * Defines single result items for album lists
13
 */
14
final class AlbumListItem implements JsonSerializable
15
{
16 2
    public function __construct(
17
        private readonly ConfigProviderInterface $config,
18
        private readonly AlbumInterface $album,
19
    ) {
20
    }
21
22
    /**
23
     * @return array{
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{ at position 2 could not be parsed: the token is null at position 2.
Loading history...
24
     *  id: int,
25
     *  artistId: int,
26
     *  artistName: string,
27
     *  name: string,
28
     *  cover: string,
29
     *  length: int
30
     * }
31
     */
32 1
    public function jsonSerialize(): array
33
    {
34 1
        $artist = $this->album->getArtist();
35 1
        $albumId = $this->album->getId();
36
37 1
        $baseUrl = $this->config->getBaseUrl();
38
39
        return [
40 1
            'id' => $albumId,
41 1
            'artistId' => $artist->getId(),
42 1
            'artistName' => (string) $artist->getTitle(),
43 1
            'name' => (string) $this->album->getTitle(),
44 1
            'cover' => sprintf('%s/art/album/%d', $baseUrl, $albumId),
45 1
            'length' => $this->album->getLength(),
46
        ];
47
    }
48
}
49