RandomSongsApplication   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 9
c 0
b 0
f 0
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 17 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Random;
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\Component\Song\RandomSongsRetrieverInterface;
13
14
final class RandomSongsApplication extends AbstractApiApplication
15
{
16
    /** @var int */
17
    private const DEFAULT_LIMIT = 100;
18
19 1
    public function __construct(
20
        private readonly RandomSongsRetrieverInterface $randomSongsRetriever,
21
        private readonly ResultItemFactoryInterface $resultItemFactory,
22
    ) {
23 1
    }
24
25 1
    protected function run(
26
        ServerRequestInterface $request,
27
        JsonEnabledResponseInterface $response,
28
        array $args
29
    ): ResponseInterface {
30 1
        $list = [];
31
32 1
        $limit = (int) ($args['limit'] ?? self::DEFAULT_LIMIT);
33
34 1
        foreach ($this->randomSongsRetriever->retrieve($limit) as $song) {
35 1
            $album = $song->getDisc()->getAlbum();
36
37 1
            $list[] = $this->resultItemFactory->createSongListItem($song, $album);
38
        }
39
40 1
        return $response->withJson(
41 1
            ['items' => $list]
42 1
        );
43
    }
44
}
45