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

SplitWarpCoreOutput   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

3 Methods

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