PlaybackHistoryApplication   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 19 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Api\Playback;
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\Message\JsonEnabledResponseInterface;
11
use Uxmp\Core\Api\Lib\ResultItemFactoryInterface;
12
use Uxmp\Core\Orm\Repository\PlaybackHistoryRepositoryInterface;
13
14
final class PlaybackHistoryApplication extends AbstractApiApplication
15
{
16
    /**
17
     * @var int
18
     */
19
    private const HISTORY_LIMIT = 15;
20
21 1
    public function __construct(
22
        private readonly PlaybackHistoryRepositoryInterface $playbackHistoryRepository,
23
        private readonly ResultItemFactoryInterface $resultItemFactory,
24
    ) {
25 1
    }
26
27 1
    protected function run(
28
        ServerRequestInterface $request,
29
        JsonEnabledResponseInterface $response,
30
        array $args
31
    ): ResponseInterface {
32 1
        $history = $this->playbackHistoryRepository->findBy(
33 1
            [],
34 1
            ['play_date' => 'DESC'],
35 1
            self::HISTORY_LIMIT
36 1
        );
37
38 1
        $result = [];
39
40 1
        foreach ($history as $item) {
41 1
            $result[] = $this->resultItemFactory->createPlaybackHistoryItem($item);
42
        }
43
44 1
        return $response->withJson(
45 1
            ['items' => $result],
46 1
        );
47
    }
48
}
49