ArtistSongsApplication   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 28
ccs 11
cts 11
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 20 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Artist;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Uxmp\Core\Api\AbstractApiApplication;
10
use Uxmp\Core\Api\Lib\Message\JsonEnabledResponseInterface;
11
use Uxmp\Core\Api\Lib\ResultItemFactoryInterface;
12
use Uxmp\Core\Orm\Repository\AlbumRepositoryInterface;
13
14
final class ArtistSongsApplication extends AbstractApiApplication
15
{
16 1
    public function __construct(
17
        private readonly AlbumRepositoryInterface $albumRepository,
18
        private readonly ResultItemFactoryInterface $resultItemFactory
19
    ) {
20 1
    }
21
22 1
    protected function run(
23
        ServerRequestInterface $request,
24
        JsonEnabledResponseInterface $response,
25
        array $args
26
    ): ResponseInterface {
27 1
        $list = [];
28
29 1
        $artistId = (int) ($args['artistId'] ?? 0);
30
31 1
        $result = $this->albumRepository->findBy(['artist_id' => $artistId], ['title' => 'ASC']);
32
33 1
        foreach ($result as $album) {
34 1
            foreach ($album->getDiscs() as $disc) {
35 1
                foreach ($disc->getSongs() as $song) {
36 1
                    $list[] = $this->resultItemFactory->createSongListItem($song, $album);
37
                }
38
            }
39
        }
40
41 1
        return $response->withJson(['items' => $list]);
42
    }
43
}
44