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

AlbumList2Responder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A writeXml() 0 11 2
A __construct() 0 3 1
A isBinaryResponder() 0 3 1
A writeJson() 0 3 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 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