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

DeactivateRPGModule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 46
ccs 0
cts 19
cp 0
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A performSessionCheck() 0 3 1
A __construct() 0 8 1
A handle() 0 22 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Action\DeactivateRPGModule;
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 DeactivateRPGModule implements ActionControllerInterface
17
{
18
    public const ACTION_IDENTIFIER = 'B_DEACTIVATE_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->deactivate(request::indInt('id'), ShipSystemTypeEnum::SYSTEM_RPG_MODULE, $game, true);
43
44
        $ship = $this->shipLoader->getByIdAndUser(
45
            request::indInt('id'),
46
            $userId
47
        );
48
49
        if ($ship->isDisabled() == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
50
            $ship->setDisabled(false);
51
        }
52
53
        $ship->setCanBeDisabled(false);
54
55
        $this->shipRepository->save($ship);
56
57
        $game->addInformation("Das RPG Modul wurde deaktiviert");
58
    }
59
    public function performSessionCheck(): bool
60
    {
61
        return true;
62
    }
63
}
64