GetAlbumMethod   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 33
c 2
b 0
f 0
dl 0
loc 58
ccs 39
cts 39
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 45 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Usox\HyperSonic\FeatureSet\V1161\Method;
6
7
use Usox\HyperSonic\Exception\ErrorCodeEnum;
8
use Usox\HyperSonic\Exception\MethodCallFailedException;
9
use Usox\HyperSonic\FeatureSet\V1161\Contract\AlbumDataProviderInterface;
10
use Usox\HyperSonic\FeatureSet\V1161\Responder\ResponderFactoryInterface;
11
use Usox\HyperSonic\Response\ResponderInterface;
12
13
/**
14
 * Retrieves and transforms data for a single album
15
 *
16
 * This class covers the `getAlbum.view` method
17
 */
18
final class GetAlbumMethod implements V1161MethodInterface
19
{
20 3
    public function __construct(
21
        private readonly ResponderFactoryInterface $responderFactory,
22
    ) {
23 3
    }
24
25
    /**
26
     * @param array<string, scalar> $queryParams
27
     * @param array<string, scalar> $args
28
     *
29
     * @throws MethodCallFailedException
30
     */
31 2
    public function __invoke(
32
        AlbumDataProviderInterface $albumDataProvider,
33
        array $queryParams,
34
        array $args,
35
    ): ResponderInterface {
36 2
        $albumId = (string) ($queryParams['id'] ?? null);
37
38 2
        $album = $albumDataProvider->getAlbum($albumId);
39
40 2
        if ($album === null) {
41 1
            throw new MethodCallFailedException(
42 1
                ErrorCodeEnum::NOT_FOUND
43 1
            );
44
        }
45
46 1
        return $this->responderFactory->createAlbumResponder(
47 1
            [
48 1
                'id' => $album['id'],
49 1
                'name' => $album['name'],
50 1
                'coverArt' => $album['coverArtId'],
51 1
                'songCount' => $album['songCount'],
52 1
                'created' => $album['createDate']->format(DATE_ATOM),
53 1
                'duration' => $album['duration'],
54 1
                'artist' => $album['artistName'],
55 1
                'artistId' => $album['artistId'],
56 1
            ],
57 1
            array_values(
58 1
                array_map(
59 1
                    static fn (array $song): array => [
60 1
                        'id' => $song['id'],
61 1
                        'isDir' => $song['isDir'],
62 1
                        'title' => $song['name'],
63 1
                        'album' => $song['albumName'],
64 1
                        'artist' => $song['artistName'],
65 1
                        'track' => $song['trackNumber'],
66 1
                        'coverArt' => $song['coverArtId'],
67 1
                        'size' => $song['size'],
68 1
                        'contentType' => $song['contentType'],
69 1
                        'duration' => $song['duration'],
70 1
                        'created' => $song['createDate']->format(DATE_ATOM),
71 1
                        'albumId' => $song['albumId'],
72 1
                        'artistId' => $song['artistId'],
73 1
                        'playCount' => $song['playCount'],
74 1
                    ],
75 1
                    $album['songs']
76 1
                )
77 1
            )
78 1
        );
79
    }
80
}
81