Passed
Push — dev ( 336cf2...bc410f )
by Janko
09:30
created

ColonyScanPanel::createBoundaries()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 12
ccs 5
cts 7
cp 0.7143
crap 3.2098
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Colony\Lib\Gui;
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 Stu\Component\Building\BuildingFunctionEnum;
9
use Stu\Component\Colony\ColonyFunctionManagerInterface;
10
use Stu\Lib\Map\VisualPanel\AbstractVisualPanel;
11
use Stu\Lib\Map\VisualPanel\Layer\DataProvider\Spacecraftcount\SpacecraftCountLayerTypeEnum;
12
use Stu\Lib\Map\VisualPanel\Layer\DataProvider\Subspace\SubspaceLayerTypeEnum;
13
use Stu\Lib\Map\VisualPanel\Layer\PanelLayerCreationInterface;
14
use Stu\Lib\Map\VisualPanel\PanelBoundaries;
15
use Stu\Lib\Map\VisualPanel\VisualPanelElementInterface;
16
use Stu\Module\Logging\LoggerUtilInterface;
17
use Stu\Orm\Entity\ColonyInterface;
18
19
class ColonyScanPanel extends AbstractVisualPanel
20
{
21 3
    public function __construct(
22
        PanelLayerCreationInterface $panelLayerCreation,
23
        private ColonyInterface $colony,
24
        private ColonyFunctionManagerInterface $colonyFunctionManager,
25
        LoggerUtilInterface $loggerUtil
26
    ) {
27 3
        parent::__construct($panelLayerCreation, $loggerUtil);
28
    }
29
30 3
    #[Override]
31
    protected function createBoundaries(): PanelBoundaries
32
    {
33 3
        $range = 1;
34
35 3
        if ($this->colonyFunctionManager->hasFunction($this->colony, BuildingFunctionEnum::BUILDING_FUNCTION_SUBSPACE_TELESCOPE)) {
36
            $range = 3;
37 3
        } elseif ($this->colonyFunctionManager->hasFunction($this->colony, BuildingFunctionEnum::BUILDING_FUNCTION_COLONY_CENTRAL)) {
38
            $range = 2;
39
        }
40
41 3
        return PanelBoundaries::fromLocation($this->colony->getStarsystemMap(), $range);
42
    }
43
44 3
    #[Override]
45
    protected function loadLayers(): void
46
    {
47 3
        $showCloaked = $this->colonyFunctionManager->hasFunction($this->colony, BuildingFunctionEnum::BUILDING_FUNCTION_COLONY_CENTRAL);
48
49 3
        $panelLayerCreation = $this->panelLayerCreation
50 3
            ->addShipCountLayer($showCloaked, null, SpacecraftCountLayerTypeEnum::ALL, 0)
51 3
            ->addSystemLayer()
52 3
            ->addAnomalyLayer()
53 3
            ->addColonyShieldLayer();
54
55 3
        if ($this->colonyFunctionManager->hasFunction($this->colony, BuildingFunctionEnum::BUILDING_FUNCTION_SUBSPACE_TELESCOPE)) {
56
            $panelLayerCreation->addSubspaceLayer($this->colony->getUser()->getId(), SubspaceLayerTypeEnum::IGNORE_USER);
57
        }
58 3
        if ($this->colonyFunctionManager->hasFunction($this->colony, BuildingFunctionEnum::BUILDING_FUNCTION_SUBSPACE_TELESCOPE)) {
59
            $panelLayerCreation->addSubspaceLayer($this->colony->getUser()->getId(), SubspaceLayerTypeEnum::IGNORE_USER);
60
        }
61
62 3
        $this->layers = $panelLayerCreation->build($this);
63
    }
64
65 3
    #[Override]
66
    protected function getEntryCallable(): callable
67
    {
68 3
        return fn(int $x, int $y): VisualPanelElementInterface => new ColonyScanPanelEntry(
69 3
            $x,
70 3
            $y,
71 3
            $this->layers
72 3
        );
73
    }
74
75 3
    #[Override]
76
    protected function getPanelViewportPercentage(): int
77
    {
78 3
        return 8;
79
    }
80
}
81