AlbumRecentApplication   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 15
c 1
b 0
f 0
dl 0
loc 37
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 24 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Album;
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\Component\Config\ConfigProviderInterface;
12
use Uxmp\Core\Orm\Repository\AlbumRepositoryInterface;
13
14
final class AlbumRecentApplication extends AbstractApiApplication
15
{
16
    /**
17
     * @var int
18
     */
19
    private const ALBUM_LIMIT = 10;
20
21 1
    public function __construct(
22
        private readonly AlbumRepositoryInterface $albumRepository,
23
        private readonly ConfigProviderInterface $config
24
    ) {
25 1
    }
26
27 1
    protected function run(
28
        ServerRequestInterface $request,
29
        JsonEnabledResponseInterface $response,
30
        array $args
31
    ): ResponseInterface {
32 1
        $baseUrl = $this->config->getBaseUrl();
33 1
        $list = [];
34
35 1
        foreach ($this->albumRepository->findBy([], ['last_modified' => 'DESC'], self::ALBUM_LIMIT) as $album) {
36 1
            $artist = $album->getArtist();
37
38 1
            $albumId = $album->getId();
39
40 1
            $list[] = [
41 1
                'id' => $albumId,
42 1
                'artistId' => $artist->getId(),
43 1
                'artistName' => $artist->getTitle(),
44 1
                'name' => $album->getTitle(),
45 1
                'cover' => sprintf('%s/art/album/%d', $baseUrl, $albumId),
46 1
                'length' => $album->getLength(),
47 1
            ];
48
        }
49
50 1
        return $response->withJson(['items' => $list]);
51
    }
52
}
53