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

ShowAggregationSystem::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\View\ShowAggregationSystem;
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\Exception\SanityCheckException;
10
use Stu\Module\Control\GameControllerInterface;
11
use Stu\Module\Control\ViewControllerInterface;
12
use Stu\Module\Commodity\CommodityTypeEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Commodity\CommodityTypeEnum 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...
13
use Stu\Module\Ship\Lib\ShipLoaderInterface;
14
use Stu\Orm\Repository\CommodityRepositoryInterface;
15
16
final class ShowAggregationSystem implements ViewControllerInterface
17
{
18
    public const VIEW_IDENTIFIER = 'SHOW_AGGREGATION_SYSTEM_AJAX';
19
20
    public function __construct(
21
        private ShipLoaderInterface $shipLoader,
22
        private CommodityRepositoryInterface $commodityRepository
23
    ) {}
24
25
    #[Override]
26
    public function handle(GameControllerInterface $game): void
27
    {
28
        $user = $game->getUser();
29
        $userId = $user->getId();
30
31
        $wrapper = $this->shipLoader->getWrapperByIdAndUser(
32
            request::indInt('id'),
33
            $userId,
34
            false,
35
            false
36
        );
37
38
        $game->setPageTitle(_('Aggregationssystem'));
39
        $game->setMacroInAjaxWindow('html/ship/aggregationsystem.twig');
40
41
        $game->setTemplateVar('WRAPPER', $wrapper);
42
43
        $aggregationsystem = $wrapper->getAggregationSystemSystemData();
44
        if ($aggregationsystem === null) {
45
            throw new SanityCheckException('no aggregation system installed', null, self::VIEW_IDENTIFIER);
46
        }
47
48
        $commodities = CommodityTypeEnum::COMMODITY_CONVERSIONS;
49
        $mode1Commodities = array_filter($commodities, fn($entry) => $entry[3] === 1);
50
        $mode2Commodities = array_filter($commodities, fn($entry) => $entry[3] === 2);
51
52
53
        $mode1Commodities = array_map(fn($entry) => [
54
            $this->commodityRepository->find($entry[0]),
55
            $this->commodityRepository->find($entry[1]),
56
            $entry[2]
57
        ], $mode1Commodities);
58
59
        $mode2Commodities = array_map(fn($entry) => [
60
            $this->commodityRepository->find($entry[0]),
61
            $this->commodityRepository->find($entry[1]),
62
            $entry[2]
63
        ], $mode2Commodities);
64
65
        $chosencommodity = $aggregationsystem->getCommodityId();
66
        $game->setTemplateVar('MODE1_COMMODITIES', $mode1Commodities);
67
        $game->setTemplateVar('MODE2_COMMODITIES', $mode2Commodities);
68
        $game->setTemplateVar('CHOSENCOMMODITY', $chosencommodity);
69
    }
70
}