Passed
Push — master ( 5a11dc...578008 )
by Janko
08:39
created

BuildingFunctionWrapper   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
eloc 51
dl 0
loc 125
ccs 27
cts 54
cp 0.5
rs 10
c 0
b 0
f 0
wmc 23

17 Methods

Rating   Name   Duplication   Size   Complexity  
A isModuleFab() 0 6 1
A getModuleFabBuildingFunctionId() 0 7 1
A isTorpedoFab() 0 4 1
A isSubspaceTelescope() 0 4 1
A isTechCenter() 0 4 1
A isAcademy() 0 4 1
A isAirfield() 0 4 1
A getSubspaceTelescopeBuildingFunctionId() 0 9 3
A isWarehouse() 0 4 1
A getTechCenterBuildingFunctionId() 0 9 3
A isFabHall() 0 4 1
A __construct() 0 1 1
A hasFunction() 0 3 1
A getShipyardBuildingFunctionId() 0 7 1
A isFighterShipyard() 0 4 1
A getFabHallBuildingFunctionId() 0 9 3
A isShipyard() 0 6 1
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\BuildingFunctionEnum;
9
use Stu\Orm\Entity\BuildingFunction;
10
11
final class BuildingFunctionWrapper implements BuildingFunctionWrapperInterface
12
{
13
    /** @param array<BuildingFunction> $buildingfunctions */
14 1
    public function __construct(private array $buildingfunctions) {}
15
16 1
    #[Override]
17
    public function isTorpedoFab(): bool
18
    {
19 1
        return $this->hasFunction(BuildingFunctionEnum::TORPEDO_FAB);
20
    }
21
22 1
    #[Override]
23
    public function isAirfield(): bool
24
    {
25 1
        return $this->hasFunction(BuildingFunctionEnum::AIRFIELD);
26
    }
27
28
    #[Override]
29
    public function isFighterShipyard(): bool
30
    {
31
        return $this->hasFunction(BuildingFunctionEnum::FIGHTER_SHIPYARD);
32
    }
33
34 1
    #[Override]
35
    public function isAcademy(): bool
36
    {
37 1
        return $this->hasFunction(BuildingFunctionEnum::ACADEMY);
38
    }
39
40 1
    #[Override]
41
    public function isFabHall(): bool
42
    {
43 1
        return $this->hasFunction(BuildingFunctionEnum::FABRICATION_HALL);
44
    }
45
46 1
    #[Override]
47
    public function isTechCenter(): bool
48
    {
49 1
        return $this->hasFunction(BuildingFunctionEnum::TECH_CENTER);
50
    }
51
52 1
    #[Override]
53
    public function isShipyard(): bool
54
    {
55 1
        return array_any(
56 1
            $this->buildingfunctions,
57 1
            fn(BuildingFunction $function): bool => $function->getFunction()->isShipyard()
58 1
        );
59
    }
60
61
    #[Override]
62
    public function getShipyardBuildingFunctionId(): ?int
63
    {
64
        return array_find(
65
            $this->buildingfunctions,
66
            fn(BuildingFunction $function): bool => $function->getFunction()->isShipyard()
67
        )?->getId();
68
    }
69
70 1
    #[Override]
71
    public function isModuleFab(): bool
72
    {
73 1
        return array_any(
74 1
            $this->buildingfunctions,
75 1
            fn(BuildingFunction $function): bool => $function->getFunction()->isModuleFab()
76 1
        );
77
    }
78
79 1
    #[Override]
80
    public function isWarehouse(): bool
81
    {
82 1
        return $this->hasFunction(BuildingFunctionEnum::WAREHOUSE);
83
    }
84
85 1
    #[Override]
86
    public function isSubspaceTelescope(): bool
87
    {
88 1
        return $this->hasFunction(BuildingFunctionEnum::SUBSPACE_TELESCOPE);
89
    }
90
91
    #[Override]
92
    public function getModuleFabBuildingFunctionId(): ?int
93
    {
94
        return array_find(
95
            $this->buildingfunctions,
96
            fn(BuildingFunction $function): bool => $function->getFunction()->isModuleFab()
97
        )?->getId();
98
    }
99
100
    #[Override]
101
    public function getFabHallBuildingFunctionId(): ?int
102
    {
103
        foreach ($this->buildingfunctions as $func) {
104
            if ($func->getFunction() === BuildingFunctionEnum::FABRICATION_HALL) {
105
                return $func->getId();
106
            }
107
        }
108
        return null;
109
    }
110
111
    #[Override]
112
    public function getTechCenterBuildingFunctionId(): ?int
113
    {
114
        foreach ($this->buildingfunctions as $func) {
115
            if ($func->getFunction() === BuildingFunctionEnum::TECH_CENTER) {
116
                return $func->getId();
117
            }
118
        }
119
        return null;
120
    }
121
122
    #[Override]
123
    public function getSubspaceTelescopeBuildingFunctionId(): ?int
124
    {
125
        foreach ($this->buildingfunctions as $func) {
126
            if ($func->getFunction() === BuildingFunctionEnum::SUBSPACE_TELESCOPE) {
127
                return $func->getId();
128
            }
129
        }
130
        return null;
131
    }
132
133 1
    private function hasFunction(BuildingFunctionEnum $function): bool
134
    {
135 1
        return array_key_exists($function->value, $this->buildingfunctions);
136
    }
137
}
138