RadioStationRetrieveApplication::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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