MusicFoldersResponder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isBinaryResponder() 0 3 1
A writeJson() 0 3 1
A writeXml() 0 13 2
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 4
    }
23
24 1
    public function writeXml(XMLArray $XMLArray): void
25
    {
26 1
        $XMLArray->startLoop(
27 1
            'musicFolders',
28 1
            [],
29 1
            function (XMLArray $XMLArray): void {
30 1
                foreach ($this->musicFolders as $musicFolder) {
31 1
                    $XMLArray->add(
32 1
                        'musicFolder',
33 1
                        '',
34 1
                        [
35 1
                            'name' => htmlspecialchars($musicFolder['name']),
36 1
                            'id' => $musicFolder['id'],
37 1
                        ]
38 1
                    );
39
                }
40 1
            }
41 1
        );
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