GenresResponder::writeXml()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 13
ccs 12
cts 12
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 GenresResponder implements FormattedResponderInterface
11
{
12
    /**
13
     * @param array<array{
14
     *  value: string,
15
     *  albumCount: int,
16
     *  songCount: int
17
     * }> $genres
18
     */
19 4
    public function __construct(
20
        private readonly array $genres
21
    ) {
22 4
    }
23
24 1
    public function writeXml(XMLArray $XMLArray): void
25
    {
26 1
        $XMLArray->startLoop(
27 1
            'genres',
28 1
            [],
29 1
            function (XMLArray $XMLArray): void {
30 1
                foreach ($this->genres as $genre) {
31 1
                    $XMLArray->add(
32 1
                        'genre',
33 1
                        htmlspecialchars($genre['value']),
34 1
                        [
35 1
                            'albumCount' => $genre['albumCount'],
36 1
                            'songCount' => $genre['songCount'],
37 1
                        ],
38 1
                    );
39
                }
40 1
            }
41 1
        );
42
    }
43
44 1
    public function writeJson(array &$root): void
45
    {
46 1
        $root['genres'] = ['genre' => $this->genres];
47
    }
48
49 1
    public function isBinaryResponder(): bool
50
    {
51 1
        return false;
52
    }
53
}
54