Passed
Push — master ( 3d0840...13d157 )
by Nico
48:12 queued 22:32
created

SplitReactorOutput::handle()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 14
c 0
b 0
f 0
nc 5
nop 1
dl 0
loc 26
ccs 0
cts 16
cp 0
crap 20
rs 9.7998
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Action\SplitReactorOutput;
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\View\ShowShip\ShowShip;
12
13
final class SplitReactorOutput implements ActionControllerInterface
14
{
15
    public const ACTION_IDENTIFIER = 'B_SPLIT_REACTOR_OUTPUT';
16
17
    private ShipLoaderInterface $shipLoader;
18
19
    public function __construct(
20
        ShipLoaderInterface $shipLoader
21
    ) {
22
        $this->shipLoader = $shipLoader;
23
    }
24
25
    public function handle(GameControllerInterface $game): void
26
    {
27
        $game->setView(ShowShip::VIEW_IDENTIFIER);
28
29
        $userId = $game->getUser()->getId();
30
31
32
        $wrapper = $this->shipLoader->getWrapperByIdAndUser(
33
            request::indInt('id'),
34
            $userId
35
        );
36
37
        $systemData = $wrapper->getWarpDriveSystemData();
38
        if ($systemData === null) {
39
            return;
40
        }
41
42
        $value = request::postInt('value');
43
        if ($value < 0) {
44
            $value = 0;
45
        }
46
        if ($value > 100) {
47
            $value = 100;
48
        }
49
50
        $systemData->setWarpDriveSplit($value)->update();
51
    }
52
53
    public function performSessionCheck(): bool
54
    {
55
        return true;
56
    }
57
}
58