ArtistsResponder::isBinaryResponder()   A
last analyzed

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 0
Metric Value
cc 1
eloc 1
c 0
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 Usox\HyperSonic\Response\FormattedResponderInterface;
9
10
final class ArtistsResponder implements FormattedResponderInterface
11
{
12
    /**
13
     * @param array{
14
     *  ignoredArticles: string,
15
     *  index: array<array{
16
     *    name: string,
17
     *    artist: array<array{
18
     *      id: string,
19
     *      name: string,
20
     *      coverArt: string,
21
     *      artistImageUrl: string,
22
     *      albumCount: int,
23
     *      starred?: string
24
     *    }>
25
     *  }>
26
     * } $artistList
27
     */
28 4
    public function __construct(
29
        private readonly array $artistList
30
    ) {
31 4
    }
32
33 1
    public function writeXml(XMLArray $XMLArray): void
34
    {
35 1
        $XMLArray->startLoop(
36 1
            'artists',
37 1
            ['ignoredArticles' => $this->artistList['ignoredArticles']],
38 1
            function (XMLArray $XMLArray): void {
39 1
                foreach ($this->artistList['index'] as $indexItem) {
40 1
                    $XMLArray->startLoop(
41 1
                        'index',
42 1
                        ['name' => $indexItem['name']],
43 1
                        static function (XMLArray $XMLArray) use ($indexItem): void {
44 1
                            foreach ($indexItem['artist'] as $artist) {
45 1
                                $XMLArray->add(
46 1
                                    'artist',
47 1
                                    null,
48 1
                                    $artist
49 1
                                );
50
                            }
51 1
                        }
52 1
                    );
53
                }
54 1
            }
55 1
        );
56
    }
57
58 1
    public function writeJson(array &$root): void
59
    {
60 1
        $root['artists'] = $this->artistList;
61
    }
62
63 1
    public function isBinaryResponder(): bool
64
    {
65 1
        return false;
66
    }
67
}
68