Passed
Push — dev ( ac26ef...6b8aca )
by Nico
08:29
created

SplitWarpCoreOutput::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Action\SplitWarpCoreOutput;
6
7
use request;
8
use Stu\Module\Control\ActionControllerInterface;
9
use Stu\Module\Control\GameControllerInterface;
10
use Stu\Module\Ship\Lib\ShipLoaderInterface;
11
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface;
12
use Stu\Module\Ship\View\ShowShip\ShowShip;
13
14
final class SplitWarpCoreOutput implements ActionControllerInterface
15
{
16
    public const ACTION_IDENTIFIER = 'B_SPLIT_WARP_CORE_OUTPUT';
17
18
    private ShipLoaderInterface $shipLoader;
19
20
    private ShipWrapperFactoryInterface $shipWrapperFactory;
21
22
23
    public function __construct(
24
        ShipWrapperFactoryInterface $shipWrapperFactory,
25
        ShipLoaderInterface $shipLoader
26
    ) {
27
        $this->shipLoader = $shipLoader;
28
        $this->shipWrapperFactory = $shipWrapperFactory;
29
    }
30
31
    public function handle(GameControllerInterface $game): void
32
    {
33
        $game->setView(ShowShip::VIEW_IDENTIFIER);
34
35
        $userId = $game->getUser()->getId();
36
37
38
        $ship = $this->shipLoader->getByIdAndUser(
39
            request::indInt('id'),
40
            $userId
41
        );
42
43
        $value = request::postInt('value');
44
        if ($value < 0) {
45
            $value = 0;
46
        }
47
        if ($value > 100) {
48
            $value = 100;
49
        }
50
        $warpcoresystem = $this->shipWrapperFactory->wrapShip($ship)->getWarpCoreSystemData();
51
52
        $warpcoresystem->setWarpCoreSplit($value)->update();
53
    }
54
55
    public function performSessionCheck(): bool
56
    {
57
        return true;
58
    }
59
}
60