RadioStationRetrieveApplication   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 10

2 Methods

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