PlaylistListByUserApplication   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
c 1
b 0
f 0
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Playlist;
6
7
use JsonSerializable;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Uxmp\Core\Api\AbstractApiApplication;
11
use Uxmp\Core\Api\Lib\Message\JsonEnabledResponseInterface;
12
use Uxmp\Core\Api\Lib\Middleware\SessionValidatorMiddleware;
13
use Uxmp\Core\Api\Lib\ResultItemFactoryInterface;
14
use Uxmp\Core\Orm\Model\PlaylistInterface;
15
use Uxmp\Core\Orm\Repository\PlaylistRepositoryInterface;
16
17
/**
18
 * Retrieve all playlists which belong to the current user
19
 */
20
final class PlaylistListByUserApplication extends AbstractApiApplication
21
{
22 1
    public function __construct(
23
        private readonly PlaylistRepositoryInterface $playlistRepository,
24
        private readonly ResultItemFactoryInterface $resultItemFactory,
25
    ) {
26 1
    }
27
28 1
    protected function run(
29
        ServerRequestInterface $request,
30
        JsonEnabledResponseInterface $response,
31
        array $args
32
    ): ResponseInterface {
33 1
        return $response->withJson([
34 1
            'items' => array_map(
35 1
                fn (PlaylistInterface $playlist): JsonSerializable => $this->resultItemFactory->createPlaylistItem($playlist),
36 1
                $this->playlistRepository->findBy(
37 1
                    ['owner' => $request->getAttribute(SessionValidatorMiddleware::USER)],
38 1
                    ['name' => 'ASC']
39 1
                )
40 1
            ),
41 1
        ]);
42
    }
43
}
44