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

SplitReactorOutput   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 43
ccs 0
cts 20
cp 0
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A performSessionCheck() 0 3 1
A __construct() 0 4 1
A handle() 0 26 4
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