PlaylistListByUserApplication::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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