ArtApplication::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 10
cc 2
nc 2
nop 3
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Art;
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\Art\ArtItemIdentifierInterface;
13
use Uxmp\Core\Component\Art\CachedArtResponseProviderInterface;
14
15
final class ArtApplication extends AbstractApiApplication
16
{
17 2
    public function __construct(
18
        private readonly CachedArtResponseProviderInterface $cachedArtResponseProvider,
19
        private readonly ArtItemIdentifierInterface $artItemIdentifier,
20
    ) {
21 2
    }
22
23 2
    protected function run(
24
        ServerRequestInterface $request,
25
        JsonEnabledResponseInterface $response,
26
        array $args
27
    ): ResponseInterface {
28 2
        $item = $this->artItemIdentifier->identify(
29 2
            sprintf(
30 2
                '%s-%d',
31 2
                $args['type'] ?? '',
32 2
                $args['id'] ?? 0
33 2
            )
34 2
        );
35
36 2
        if ($item === null) {
37 1
            return $response->withStatus(Http::NOT_FOUND);
38
        }
39
40 1
        return $this->cachedArtResponseProvider->withCachedArt($response, $item);
41
    }
42
}
43