PlaylistDeletionApplication::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

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