ArtistApplication::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.9666
cc 2
nc 2
nop 3
crap 2
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 Teapot\StatusCode\Http;
10
use Uxmp\Core\Api\AbstractApiApplication;
11
use Uxmp\Core\Api\Lib\Message\JsonEnabledResponseInterface;
12
use Uxmp\Core\Component\Config\ConfigProviderInterface;
13
use Uxmp\Core\Orm\Repository\ArtistRepositoryInterface;
14
15
final class ArtistApplication extends AbstractApiApplication
16
{
17 2
    public function __construct(
18
        private readonly ArtistRepositoryInterface $artistRepository,
19
        private readonly ConfigProviderInterface $config
20
    ) {
21 2
    }
22
23 2
    protected function run(
24
        ServerRequestInterface $request,
25
        JsonEnabledResponseInterface $response,
26
        array $args
27
    ): ResponseInterface {
28 2
        $artistId = (int) ($args['artistId'] ?? 0);
29
30 2
        $artist = $this->artistRepository->find($artistId);
31
32 2
        if ($artist === null) {
33 1
            return $response->withStatus(Http::NOT_FOUND);
34
        }
35
36 1
        return $response->withJson(
37 1
            [
38 1
                'id' => $artistId,
39 1
                'name' => $artist->getTitle(),
40 1
                'cover' => sprintf('%s/art/artist/%d', $this->config->getBaseUrl(), $artistId),
41 1
                'mbId' => $artist->getMbid(),
42 1
            ]
43 1
        );
44
    }
45
}
46