Passed
Push — main ( cff59a...745121 )
by Daniel
02:18
created

AlbumList2Responder::writeJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Usox\HyperSonic\FeatureSet\V1161\Responder;
6
7
use AaronDDM\XMLBuilder\XMLArray;
8
use Traversable;
9
use Usox\HyperSonic\Response\FormattedResponderInterface;
10
11
final class AlbumList2Responder implements FormattedResponderInterface
12
{
13
    /**
14
     * @param Traversable<array{
15
     *  id: string,
16
     *  name: string,
17
     *  coverArt: string,
18
     *  songCount: int,
19
     *  created: string,
20
     *  duration: int,
21
     *  artist: string,
22
     *  artistId: string,
23
     * }> $albumList
24
     */
25 4
    public function __construct(
26
        private readonly Traversable $albumList,
27
    ) {
28
    }
29
30 1
    public function writeXml(XMLArray $XMLArray): void
31
    {
32 1
        $XMLArray->startLoop(
33
            'albumList2',
34 1
            [],
35 1
            function (XMLArray $XMLArray): void {
36 1
                foreach ($this->albumList as $album) {
37 1
                    $XMLArray->add(
38
                        'album',
39
                        null,
40
                        $album
41
                    );
42
                }
43
            }
44
        );
45
    }
46
47 1
    public function writeJson(array &$root): void
48
    {
49 1
        $root['albumList2'] = ['album' => iterator_to_array($this->albumList)];
50
    }
51
52 1
    public function isBinaryResponder(): bool
53
    {
54 1
        return false;
55
    }
56
}
57