Passed
Push — main ( 8c3aba...bef14c )
by Daniel
02:58
created

MusicFoldersResponder::isBinaryResponder()   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
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 MusicFoldersResponder implements FormattedResponderInterface
12
{
13
    /**
14
     * @param Traversable<array{
15
     *  name: string,
16
     *  id: string
17
     * }> $musicFolders
18
     */
19 4
    public function __construct(
20
        private readonly Traversable $musicFolders
21
    ) {
22
    }
23
24 1
    public function writeXml(XMLArray $XMLArray): void
25
    {
26 1
        $XMLArray->startLoop(
27
            'musicFolders',
28 1
            [],
29 1
            function (XMLArray $XMLArray): void {
30 1
                foreach ($this->musicFolders as $musicFolder) {
31 1
                    $XMLArray->add(
32
                        'musicFolder',
33
                        '',
34
                        [
35 1
                            'name' => htmlspecialchars($musicFolder['name']),
36 1
                            'id' => $musicFolder['id'],
37
                        ]
38
                    );
39
                }
40
            }
41
        );
42
    }
43
44 1
    public function writeJson(array &$root): void
45
    {
46 1
        $root['musicFolders'] = ['musicFolder' => iterator_to_array($this->musicFolders)];
47
    }
48
49 1
    public function isBinaryResponder(): bool
50
    {
51 1
        return false;
52
    }
53
}
54