Passed
Push — dev ( ff3b26...5458f8 )
by Nico
20:18
created

ActivateRPGModule::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 19
ccs 0
cts 11
cp 0
crap 2
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Action\ActivateRPGModule;
6
7
use request;
8
use Stu\Component\Ship\System\ShipSystemTypeEnum;
9
use Stu\Module\Control\ActionControllerInterface;
10
use Stu\Module\Control\GameControllerInterface;
11
use Stu\Module\Ship\Lib\ActivatorDeactivatorHelperInterface;
12
use Stu\Module\Ship\View\ShowShip\ShowShip;
13
use Stu\Module\Ship\Lib\ShipLoaderInterface;
14
use Stu\Orm\Repository\ShipRepositoryInterface;
15
16
final class ActivateRPGModule implements ActionControllerInterface
17
{
18
    public const ACTION_IDENTIFIER = 'B_ACTIVATE_RPG_MODULE';
19
20
    private ActivatorDeactivatorHelperInterface $helper;
21
22
    private ShipLoaderInterface $shipLoader;
23
24
    private ShipRepositoryInterface $shipRepository;
25
26
    public function __construct(
27
        ShipLoaderInterface $shipLoader,
28
        ShipRepositoryInterface $shipRepository,
29
        ActivatorDeactivatorHelperInterface $helper
30
    ) {
31
        $this->shipLoader = $shipLoader;
32
        $this->shipRepository = $shipRepository;
33
        $this->helper = $helper;
34
    }
35
36
    public function handle(GameControllerInterface $game): void
37
    {
38
        $game->setView(ShowShip::VIEW_IDENTIFIER);
39
40
        $userId = $game->getUser()->getId();
41
42
        $this->helper->activate(request::indInt('id'), ShipSystemTypeEnum::SYSTEM_RPG_MODULE, $game, true);
43
44
        $ship = $this->shipLoader->getByIdAndUser(
45
            request::indInt('id'),
46
            $userId
47
        );
48
49
50
        $ship->setCanBeDisabled(true);
51
52
        $this->shipRepository->save($ship);
53
54
        $game->addInformation("Das RPG Modul wurde aktiviert");
55
    }
56
57
    public function performSessionCheck(): bool
58
    {
59
        return true;
60
    }
61
}
62