Passed
Push — master ( b559d8...779d9f )
by Nico
10:31
created

RpgRanking::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 16
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 23
ccs 0
cts 22
cp 0
crap 2
rs 9.7333
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Database\View\RpgRanking;
6
7
use Stu\Module\Control\GameControllerInterface;
8
use Stu\Module\Control\ViewControllerInterface;
9
use Stu\Module\Database\Lib\DatabaseTopListWithPoints;
10
use Stu\Module\Database\Lib\DatabaseUiFactoryInterface;
11
use Stu\Orm\Repository\KnPostRepositoryInterface;
12
13
final class RpgRanking implements ViewControllerInterface
14
{
15
    public const VIEW_IDENTIFIER = 'SHOW_TOP_RPG';
16
17
    private DatabaseUiFactoryInterface $databaseUiFactory;
18
19
    private KnPostRepositoryInterface $knPostRepository;
20
21
    public function __construct(
22
        DatabaseUiFactoryInterface $databaseUiFactory,
23
        KnPostRepositoryInterface $knPostRepository
24
    ) {
25
        $this->databaseUiFactory = $databaseUiFactory;
26
        $this->knPostRepository = $knPostRepository;
27
    }
28
29
    public function handle(GameControllerInterface $game): void
30
    {
31
        $game->appendNavigationPart(
32
            'database.php',
33
            'Datenbank'
34
        );
35
        $game->appendNavigationPart(
36
            sprintf(
37
                'database.php?%s=1',
38
                static::VIEW_IDENTIFIER
39
            ),
40
            'Die 10 bestbewerteten RPG-Schreiber'
41
        );
42
        $game->setPageTitle('/ Datenbank / Die 10 bestbewerteten RPG-Schreiber');
43
        $game->showMacro('html/database.xhtml/top_rpg_user');
44
        $game->setTemplateVar(
45
            'PRESTIGE_LIST',
46
            array_map(
47
                fn (array $data): DatabaseTopListWithPoints => $this->databaseUiFactory->createDatabaseTopListWithPoints($data['user_id'], (string) $data['votes']),
48
                $this->knPostRepository->getRpgVotesTop10()
49
            )
50
        );
51
        $game->setTemplateVar('USER_COUNT', $this->knPostRepository->getRpgVotesOfUser($game->getUser()));
52
    }
53
}
54