Passed
Push — dev ( 238307...62244f )
by Nico
26:37
created

TransformResources   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 54
ccs 0
cts 28
cp 0
rs 10
c 1
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 37 5
A performSessionCheck() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Action\Mining;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use request;
9
use Stu\Component\Ship\System\ShipSystemTypeEnum;
10
use Stu\Exception\SanityCheckException;
11
use Stu\Module\Control\ActionControllerInterface;
12
use Stu\Module\Control\GameControllerInterface;
13
use Stu\Module\Ship\Lib\ActivatorDeactivatorHelperInterface;
14
use Stu\Module\Ship\Lib\ShipLoaderInterface;
15
use Stu\Module\Ship\View\ShowShip\ShowShip;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Ship\View\ShowShip\ShowShip was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
18
final class TransformResources implements ActionControllerInterface
19
{
20
    public const ACTION_IDENTIFIER = 'B_TRANSFORM_RESOURCES';
21
22
    public function __construct(
23
        private ShipLoaderInterface $shipLoader,
24
        private ActivatorDeactivatorHelperInterface $helper
25
    ) {}
26
27
    #[Override]
28
    public function handle(GameControllerInterface $game): void
29
    {
30
        $game->setView(ShowShip::VIEW_IDENTIFIER);
31
32
        $userId = $game->getUser()->getId();
33
        $shipId = request::indInt('id');
34
35
        $wrapper = $this->shipLoader->getWrapperByIdAndUser(
36
            $shipId,
37
            $userId
38
        );
39
40
        $ship = $wrapper->get();
41
        $aggregationsystem = $wrapper->getAggregationSystemSystemData();
42
43
        if ($aggregationsystem === null) {
44
            throw new SanityCheckException('collector = null ', self::ACTION_IDENTIFIER);
45
        }
46
47
        $commodityId = request::postInt('chosen');
48
49
        if ($commodityId === 0) {
50
            if ($ship->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_AGGREGATION_SYSTEM)) {
51
                $this->helper->deactivate($wrapper, ShipSystemTypeEnum::SYSTEM_AGGREGATION_SYSTEM, $game);
52
                $aggregationsystem->setCommodityId($commodityId)->update();
53
            }
54
            return;
55
        } else {
56
57
58
            if (!$this->helper->activate($wrapper, ShipSystemTypeEnum::SYSTEM_AGGREGATION_SYSTEM, $game)) {
59
                return;
60
            }
61
            $aggregationsystem->setCommodityId($commodityId)->update();
62
            $game->addInformationf(
63
                "Ressourcen werden umgewandelt",
64
            );
65
        }
66
    }
67
68
    #[Override]
69
    public function performSessionCheck(): bool
70
    {
71
        return true;
72
    }
73
}