Passed
Push — master ( f4068b...77f637 )
by Nico
40:27 queued 14:09
created

StopTakeover::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
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
nc 2
nop 1
dl 0
loc 26
ccs 0
cts 17
cp 0
crap 6
rs 9.7666
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Action\StopTakeover;
6
7
use request;
8
use Stu\Module\Control\ActionControllerInterface;
9
use Stu\Module\Control\GameControllerInterface;
10
use Stu\Module\Ship\Lib\Interaction\ShipTakeoverManagerInterface;
11
use Stu\Module\Ship\Lib\ShipLoaderInterface;
12
use Stu\Module\Ship\View\ShowShip\ShowShip;
13
14
final class StopTakeover implements ActionControllerInterface
15
{
16
    public const ACTION_IDENTIFIER = 'B_STOP_TAKEOVER';
17
18
    private ShipLoaderInterface $shipLoader;
19
20
    private ShipTakeoverManagerInterface $shipTakeoverManager;
21
22
    public function __construct(
23
        ShipLoaderInterface $shipLoader,
24
        ShipTakeoverManagerInterface $shipTakeoverManager
25
    ) {
26
        $this->shipLoader = $shipLoader;
27
        $this->shipTakeoverManager = $shipTakeoverManager;
28
    }
29
30
    public function handle(GameControllerInterface $game): void
31
    {
32
        $game->setView(ShowShip::VIEW_IDENTIFIER);
33
34
        $user = $game->getUser();
35
        $userId = $user->getId();
36
37
        $shipId = request::getIntFatal('id');
38
39
        $wrapper = $this->shipLoader->getWrapperByIdAndUser(
40
            $shipId,
41
            $userId
42
        );
43
44
        $ship = $wrapper->get();
45
46
        $takeover = $ship->getTakeoverActive();
47
        if ($takeover === null) {
48
            return;
49
        }
50
51
        $this->shipTakeoverManager->cancelTakeover($takeover);
52
53
        $game->addInformationf(
54
            'Übernahme der %s wurde abgebrochen',
55
            $takeover->getTargetShip()->getName()
56
        );
57
    }
58
59
    public function performSessionCheck(): bool
60
    {
61
        return true;
62
    }
63
}
64