Passed
Branch main (69b1a6)
by Daniel
12:24
created

AlbumResponder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 63
ccs 12
cts 12
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isBinaryResponder() 0 3 1
A writeXml() 0 16 2
A __construct() 0 4 1
A writeJson() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Usox\HyperSonic\FeatureSet\V1161\Responder;
6
7
use AaronDDM\XMLBuilder\XMLArray;
8
use Usox\HyperSonic\Response\FormattedResponderInterface;
9
10
final class AlbumResponder implements FormattedResponderInterface
11
{
12
    /**
13
     * @param array{
14
     *  id: string,
15
     *  name: string,
16
     *  coverArt: string,
17
     *  songCount: int,
18
     *  created: string,
19
     *  duration: int,
20
     *  artist: string,
21
     *  artistId: string,
22
     * } $album
23
     * @param array<array{
24
     *  id: string,
25
     *  isDir: bool,
26
     *  title: string,
27
     *  album: string,
28
     *  artist: string,
29
     *  track: int,
30
     *  coverArt: string,
31
     *  size: int,
32
     *  contentType: string,
33
     *  duration: int,
34
     *  created: string,
35
     *  albumId: string,
36
     *  artistId: string,
37
     *  playCount: int,
38
     * }> $songs
39
     */
40 4
    public function __construct(
41
        private readonly array $album,
42
        private readonly array $songs,
43
    ) {
44
    }
45
46 1
    public function writeXml(XMLArray $XMLArray): void
47
    {
48 1
        $albumNode = $XMLArray->start(
49
            'album',
50 1
            $this->album,
51
        );
52
53 1
        foreach ($this->songs as $song) {
54 1
            $albumNode->add(
55
                'song',
56
                null,
57
                $song
58
            );
59
        }
60
61 1
        $albumNode->end();
62
    }
63
64 1
    public function writeJson(array &$root): void
65
    {
66 1
        $root['album'] = $this->album;
67 1
        $root['album']['song'] = $this->songs;
68
    }
69
70 1
    public function isBinaryResponder(): bool
71
    {
72 1
        return false;
73
    }
74
}
75