Passed
Push — master ( f50aa1...d726cb )
by Nico
57:47 queued 28:23
created

BuildingFunctionWrapper::hasFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Colony\Lib;
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\BuildingEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Building\BuildingEnum 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...
9
use Stu\Module\Building\BuildingFunctionTypeEnum;
10
use Stu\Orm\Entity\BuildingFunctionInterface;
11
12
final class BuildingFunctionWrapper implements BuildingFunctionWrapperInterface
13
{
14
    /** @param array<BuildingFunctionInterface> $buildingfunctions */
15
    public function __construct(private array $buildingfunctions)
16
    {
17
    }
18
19
    #[Override]
20
    public function isTorpedoFab(): bool
21
    {
22
        return $this->hasFunction(BuildingEnum::BUILDING_FUNCTION_TORPEDO_FAB);
23
    }
24
25
    #[Override]
26
    public function isAirfield(): bool
27
    {
28
        return $this->hasFunction(BuildingEnum::BUILDING_FUNCTION_AIRFIELD);
29
    }
30
31
    #[Override]
32
    public function isFighterShipyard(): bool
33
    {
34
        return $this->hasFunction(BuildingEnum::BUILDING_FUNCTION_FIGHTER_SHIPYARD);
35
    }
36
37
    #[Override]
38
    public function isAcademy(): bool
39
    {
40
        return $this->hasFunction(BuildingEnum::BUILDING_FUNCTION_ACADEMY);
41
    }
42
43
    #[Override]
44
    public function isFabHall(): bool
45
    {
46
        return $this->hasFunction(BuildingEnum::BUILDING_FUNCTION_FABRICATION_HALL);
47
    }
48
49
    #[Override]
50
    public function isTechCenter(): bool
51
    {
52
        return $this->hasFunction(BuildingEnum::BUILDING_FUNCTION_TECH_CENTER);
53
    }
54
55
    #[Override]
56
    public function isShipyard(): bool
57
    {
58
        foreach ($this->buildingfunctions as $func) {
59
            if (in_array($func->getFunction(), BuildingFunctionTypeEnum::getShipyardOptions())) {
60
                return true;
61
            }
62
        }
63
        return false;
64
    }
65
66
    #[Override]
67
    public function getShipyardBuildingFunctionId(): ?int
68
    {
69
        foreach ($this->buildingfunctions as $func) {
70
            if (in_array($func->getFunction(), BuildingFunctionTypeEnum::getShipyardOptions())) {
71
                return $func->getId();
72
            }
73
        }
74
        return null;
75
    }
76
77
    #[Override]
78
    public function isModuleFab(): bool
79
    {
80
        foreach ($this->buildingfunctions as $func) {
81
            if (in_array($func->getFunction(), BuildingFunctionTypeEnum::getModuleFabOptions())) {
82
                return true;
83
            }
84
        }
85
        return false;
86
    }
87
88
    #[Override]
89
    public function isWarehouse(): bool
90
    {
91
        return $this->hasFunction(BuildingEnum::BUILDING_FUNCTION_WAREHOUSE);
92
    }
93
94
    #[Override]
95
    public function isSubspaceTelescope(): bool
96
    {
97
        return $this->hasFunction(BuildingEnum::BUILDING_FUNCTION_SUBSPACE_TELESCOPE);
98
    }
99
100
    #[Override]
101
    public function getModuleFabBuildingFunctionId(): ?int
102
    {
103
        foreach ($this->buildingfunctions as $func) {
104
            if (in_array($func->getFunction(), BuildingFunctionTypeEnum::getModuleFabOptions())) {
105
                return $func->getId();
106
            }
107
        }
108
        return null;
109
    }
110
111
    #[Override]
112
    public function getFabHallBuildingFunctionId(): ?int
113
    {
114
        foreach ($this->buildingfunctions as $func) {
115
            if ($func->getFunction() === BuildingEnum::BUILDING_FUNCTION_FABRICATION_HALL) {
116
                return $func->getId();
117
            }
118
        }
119
        return null;
120
    }
121
122
    #[Override]
123
    public function getTechCenterBuildingFunctionId(): ?int
124
    {
125
        foreach ($this->buildingfunctions as $func) {
126
            if ($func->getFunction() === BuildingEnum::BUILDING_FUNCTION_TECH_CENTER) {
127
                return $func->getId();
128
            }
129
        }
130
        return null;
131
    }
132
133
    #[Override]
134
    public function getSubspaceTelescopeBuildingFunctionId(): ?int
135
    {
136
        foreach ($this->buildingfunctions as $func) {
137
            if ($func->getFunction() === BuildingEnum::BUILDING_FUNCTION_SUBSPACE_TELESCOPE) {
138
                return $func->getId();
139
            }
140
        }
141
        return null;
142
    }
143
144
    private function hasFunction(int $functionId): bool
145
    {
146
        return array_key_exists($functionId, $this->buildingfunctions);
147
    }
148
}
149