PlaylistDeletionApplication   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 22 2
A __construct() 0 3 1
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 Uxmp\Core\Api\AbstractApiApplication;
10
use Uxmp\Core\Api\Lib\Component\OwnerValidationTrait;
11
use Uxmp\Core\Api\Lib\Exception\AccessViolation;
12
use Uxmp\Core\Api\Lib\Message\JsonEnabledResponseInterface;
13
use Uxmp\Core\Orm\Repository\PlaylistRepositoryInterface;
14
15
/**
16
 * Playlist deletion
17
 */
18
final class PlaylistDeletionApplication extends AbstractApiApplication
19
{
20
    use OwnerValidationTrait;
21
22 2
    public function __construct(
23
        private readonly PlaylistRepositoryInterface $playlistRepository,
24
    ) {
25 2
    }
26
27
    /**
28
     * @throws AccessViolation
29
     */
30 2
    protected function run(
31
        ServerRequestInterface $request,
32
        JsonEnabledResponseInterface $response,
33
        array $args
34
    ): ResponseInterface {
35 2
        $playlistId = (int) ($args['playlistId'] ?? 0);
36
37 2
        $playlist = $this->playlistRepository->find($playlistId);
38
39 2
        $result = false;
40
41 2
        if ($playlist !== null) {
42 1
            $this->validateOwner($request, $playlist);
43
44 1
            $this->playlistRepository->delete($playlist);
45
46 1
            $result = true;
47
        }
48
49 2
        return $response->withJson(
50 2
            [
51 2
                'result' => $result,
52 2
            ]
53 2
        );
54
    }
55
}
56