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

AlbumResponder::writeXml()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 16
ccs 6
cts 6
cp 1
crap 2
rs 9.9666
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