FavoriteRemoveApplication   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A run() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\User;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Teapot\StatusCode\Http;
10
use Uxmp\Core\Api\Lib\Message\JsonEnabledResponseInterface;
11
use Uxmp\Core\Api\Lib\Middleware\SessionValidatorMiddleware;
12
use Uxmp\Core\Api\Lib\SchemaValidatorInterface;
13
use Uxmp\Core\Component\Favorite\FavoriteManagerInterface;
14
use Uxmp\Core\Orm\Model\UserInterface;
15
use Uxmp\Core\Orm\Repository\AlbumRepositoryInterface;
16
use Uxmp\Core\Orm\Repository\SongRepositoryInterface;
17
18
/**
19
 * Remove an item from the users favorites
20
 */
21
final class FavoriteRemoveApplication extends AbstractFavoriteApplication
22
{
23 3
    public function __construct(
24
        SongRepositoryInterface $songRepository,
25
        AlbumRepositoryInterface $albumRepository,
26
        private readonly FavoriteManagerInterface $favoriteManager,
27
        SchemaValidatorInterface $schemaValidator,
28
    ) {
29 3
        parent::__construct(
30 3
            $songRepository,
31 3
            $albumRepository,
32 3
            $schemaValidator,
33 3
        );
34
    }
35
36 3
    protected function run(
37
        ServerRequestInterface $request,
38
        JsonEnabledResponseInterface $response,
39
        array $args
40
    ): ResponseInterface {
41 3
        $obj = $this->getItem($request, $args);
42
43 3
        if ($obj === null) {
44 1
            return $response->withStatus(Http::NOT_FOUND);
45
        }
46
47
        /** @var UserInterface $user */
48 2
        $user = $request->getAttribute(SessionValidatorMiddleware::USER);
49
50 2
        return $response->withJson([
51 2
            'result' => $this->favoriteManager->remove($obj, $user),
52 2
        ]);
53
    }
54
}
55