ArtApplication   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
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 26
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 18 2
A __construct() 0 4 1
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