Passed
Push — main ( 549254...757986 )
by Daniel
03:27
created

ArtistApplication::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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