PlaylistRetrieveApplication   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A run() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Playlist;
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\PlaylistRepositoryInterface;
13
14
/**
15
 * Retrieves a playlist
16
 */
17
final class PlaylistRetrieveApplication extends AbstractApiApplication
18
{
19 2
    public function __construct(
20
        private readonly PlaylistRepositoryInterface $playlistRepository,
21
    ) {
22 2
    }
23
24 2
    protected function run(
25
        ServerRequestInterface $request,
26
        JsonEnabledResponseInterface $response,
27
        array $args
28
    ): ResponseInterface {
29 2
        $playlistId = (int) ($args['playlistId'] ?? 0);
30
31 2
        $playlist = $this->playlistRepository->find($playlistId);
32
33 2
        if ($playlist === null) {
34 1
            return $response->withStatus(Http::NOT_FOUND);
35
        }
36
37 1
        return $response->withJson(
38 1
            [
39 1
                'id' => $playlist->getId(),
40 1
                'name' => $playlist->getName(),
41 1
            ]
42 1
        );
43
    }
44
}
45