RadioStationRetrieveApplication::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 16
ccs 9
cts 9
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\RadioStation;
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\Orm\Repository\RadioStationRepositoryInterface;
13
14
/**
15
 * Retrieves a radio station
16
 */
17
final class RadioStationRetrieveApplication extends AbstractApiApplication
18
{
19 2
    public function __construct(
20
        private readonly RadioStationRepositoryInterface $radioStationRepository,
21
    ) {
22 2
    }
23
24 2
    protected function run(
25
        ServerRequestInterface $request,
26
        JsonEnabledResponseInterface $response,
27
        array $args
28
    ): ResponseInterface {
29 2
        $stationId = (int) ($args['stationId'] ?? 0);
30
31 2
        $station = $this->radioStationRepository->find($stationId);
32 2
        if ($station === null) {
33 1
            return $response->withStatus(Http::NOT_FOUND);
34
        }
35
36 1
        return $response->withJson([
37 1
            'id' => $station->getId(),
38 1
            'name' => $station->getName(),
39 1
            'url' => $station->getUrl(),
40 1
        ]);
41
    }
42
}
43