Passed
Push — master ( 26f240...a6e052 )
by Nico
64:14 queued 29:51
created

ShowShipCreator::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 15
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 20
ccs 0
cts 16
cp 0
crap 6
rs 9.7666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\NPC\View\ShowShipCreator;
6
7
use request;
8
use Stu\Module\Control\GameControllerInterface;
9
use Stu\Module\Control\ViewControllerInterface;
10
use Stu\Orm\Repository\ShipBuildplanRepositoryInterface;
11
use Stu\Orm\Repository\UserRepositoryInterface;
12
use Stu\Orm\Repository\LayerRepositoryInterface;
13
14
final class ShowShipCreator implements ViewControllerInterface
15
{
16
    public const VIEW_IDENTIFIER = 'SHOW_SHIP_CREATOR';
17
18
    private ShipBuildplanRepositoryInterface $shipBuildplanRepository;
19
    private UserRepositoryInterface $userRepository;
20
    private LayerRepositoryInterface $layerRepository;
21
22
    public function __construct(
23
        ShipBuildplanRepositoryInterface $shipBuildplanRepository,
24
        UserRepositoryInterface $userRepository,
25
        LayerRepositoryInterface $layerRepository
26
    ) {
27
        $this->shipBuildplanRepository = $shipBuildplanRepository;
28
        $this->userRepository = $userRepository;
29
        $this->layerRepository = $layerRepository;
30
    }
31
32
    public function handle(GameControllerInterface $game): void
33
    {
34
        $userId = request::getInt('userId');
35
36
        $game->setTemplateFile('html/npc/shipCreator.twig');
37
        $game->appendNavigationPart('/npc/index.php?SHOW_SHIP_CREATOR=1', 'Schiff erstellen');
38
        $game->setPageTitle('Schiff erstellen');
39
40
        if ($userId > 0) {
41
            $selectedUser = $this->userRepository->find($userId);
42
            $game->setTemplateVar('USER_ID', $userId);
43
            $game->setTemplateVar('SELECTED_USER', $selectedUser);
44
            $game->setTemplateVar('BUILDPLANS', $this->shipBuildplanRepository->getByUser($userId));
45
            $game->setTemplateVar('LAYERS', $this->layerRepository->findAll());
46
        } else {
47
            $allUsers = array_merge(
48
                $this->userRepository->getNpcList(),
0 ignored issues
show
Bug introduced by
$this->userRepository->getNpcList() of type iterable is incompatible with the type array expected by parameter $arrays of array_merge(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
                /** @scrutinizer ignore-type */ $this->userRepository->getNpcList(),
Loading history...
49
                $this->userRepository->getNonNpcList()
50
            );
51
            $game->setTemplateVar('ALL_USERS', $allUsers);
52
        }
53
    }
54
}