Test Failed
Push — main ( 3531fe...1eb5c2 )
by Daniel
04:35
created

ArtistListItem::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 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\ArtistInterface;
10
11
/**
12
 * Defines single result items for artist lists
13
 */
14
final class ArtistListItem implements JsonSerializable
15
{
16
    public function __construct(
17
        private readonly ConfigProviderInterface $config,
18
        private readonly ArtistInterface $artist,
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
     *  year: ?int
31
     * }
32
     */
33
    public function jsonSerialize(): array
34
    {
35
        $artistId = $this->artist->getId();
36
37
        return [
38
            'id' => $artistId,
39
            'name' => $this->artist->getTitle(),
40
            'cover' => sprintf('%s/art/artist/%d', $this->config->getBaseUrl(), $artistId),
41
        ];
42
    }
43
}
44