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

ColonyMenuEnum::isBuildingFunctionMandatory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Colony;
6
7
use Stu\Component\Building\BuildingFunctionEnum;
8
use Stu\Module\Colony\Component\ColonyComponentEnum;
9
use Stu\Module\Colony\View\ShowAcademy\ShowAcademy;
10
use Stu\Module\Colony\View\ShowAirfield\ShowAirfield;
11
use Stu\Module\Colony\View\ShowBuildingManagement\ShowBuildingManagement;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Colony\View\S...\ShowBuildingManagement 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...
12
use Stu\Module\Colony\View\ShowBuildMenu\ShowBuildMenu;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Colony\View\ShowBuildMenu\ShowBuildMenu 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\Colony\View\ShowBuildPlans\ShowBuildPlans;
14
use Stu\Module\Colony\View\ShowFighterShipyard\ShowFighterShipyard;
15
use Stu\Module\Colony\View\ShowMainscreen\ShowMainscreen;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Colony\View\S...inscreen\ShowMainscreen 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
use Stu\Module\Colony\View\ShowManagement\ShowManagement;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Colony\View\S...nagement\ShowManagement 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...
17
use Stu\Module\Colony\View\ShowMisc\ShowMisc;
18
use Stu\Module\Colony\View\ShowModuleFab\ShowModuleFab;
19
use Stu\Module\Colony\View\ShowShipDisassembly\ShowShipDisassembly;
20
use Stu\Module\Colony\View\ShowShipRepair\ShowShipRepair;
21
use Stu\Module\Colony\View\ShowShipRetrofit\ShowShipRetrofit;
22
use Stu\Module\Colony\View\ShowShipyard\ShowShipyard;
23
use Stu\Module\Colony\View\ShowSocial\ShowSocial;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Colony\View\ShowSocial\ShowSocial 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...
24
use Stu\Module\Colony\View\ShowSubspaceTelescope\ShowSubspaceTelescope;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Colony\View\S...e\ShowSubspaceTelescope 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...
25
use Stu\Module\Colony\View\ShowTorpedoFab\ShowTorpedoFab;
26
use Stu\Module\Colony\View\ShowWaste\ShowWaste;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Colony\View\ShowWaste\ShowWaste 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...
27
28
enum ColonyMenuEnum: int
29
{
30
    case MENU_MAINSCREEN = 0;
31
    case MENU_BUILD = 1;
32
    case MENU_INFO = 2;
33
    case MENU_OPTION = 3;
34
    case MENU_SOCIAL = 4;
35
    case MENU_BUILDINGS = 5;
36
    case MENU_AIRFIELD = 6;
37
    case MENU_MODULEFAB = 7;
38
    case MENU_SHIPYARD = 8;
39
    case MENU_BUILDPLANS = 9;
40
    case MENU_FIGHTER_SHIPYARD = 10;
41
    case MENU_TORPEDOFAB = 11;
42
    case MENU_ACADEMY = 12;
43
    case MENU_WASTE = 13;
44
    case MENU_FAB_HALL = 14;
45
    case MENU_TECH_CENTER = 15;
46
    case MENU_SUBSPACE_TELESCOPE = 16;
47
    case MENU_SHIP_DISASSEMBLY = 17;
48
    case MENU_SHIP_REPAIR = 18;
49
    case MENU_SHIP_RETROFIT = 19;
50
51 2
    public static function getFor(mixed $value): ColonyMenuEnum
52
    {
53 2
        if ($value === null) {
54 2
            return self::MENU_MAINSCREEN;
55
        }
56
57
        if ($value instanceof self) {
58
            return $value;
59
        }
60
61
        return self::tryFrom($value) ?? self::MENU_MAINSCREEN;
62
    }
63
64 5
    public static function getMenuClass(ColonyMenuEnum $currentMenu, int $value): string
65
    {
66 5
        if ($currentMenu->value === $value) {
67 5
            return 'selected';
68
        }
69
70 5
        return "";
71
    }
72
73
    public function isBuildingFunctionMandatory(): bool
74
    {
75
        return match ($this) {
76
            self::MENU_SHIPYARD,
77
            self::MENU_SHIP_REPAIR,
78
            self::MENU_SHIP_DISASSEMBLY,
79
            self::MENU_BUILDPLANS,
80
            self::MENU_SHIP_RETROFIT => true,
81
            default => false
82
        };
83
    }
84
85
    /** @return array<BuildingFunctionEnum>|null */
86
    public function getNeededBuildingFunction(): ?array
87
    {
88
        return match ($this) {
89
            self::MENU_AIRFIELD => [BuildingFunctionEnum::AIRFIELD],
90
            self::MENU_MODULEFAB => BuildingFunctionEnum::getModuleFabs(),
91
            self::MENU_SHIPYARD => BuildingFunctionEnum::getShipyards(),
92
            self::MENU_BUILDPLANS => BuildingFunctionEnum::getShipyards(),
93
            self::MENU_FIGHTER_SHIPYARD => [BuildingFunctionEnum::FIGHTER_SHIPYARD],
94
            self::MENU_TORPEDOFAB => [BuildingFunctionEnum::TORPEDO_FAB],
95
            self::MENU_ACADEMY => [BuildingFunctionEnum::ACADEMY],
96
            self::MENU_WASTE => [BuildingFunctionEnum::WAREHOUSE],
97
            self::MENU_FAB_HALL => [BuildingFunctionEnum::FABRICATION_HALL],
98
            self::MENU_TECH_CENTER => [BuildingFunctionEnum::TECH_CENTER],
99
            self::MENU_SUBSPACE_TELESCOPE => [BuildingFunctionEnum::SUBSPACE_TELESCOPE],
100
            self::MENU_SHIP_DISASSEMBLY => BuildingFunctionEnum::getShipyards(),
101
            self::MENU_SHIP_REPAIR => BuildingFunctionEnum::getShipyards(),
102
            self::MENU_SHIP_RETROFIT => BuildingFunctionEnum::getShipyards(),
103
            default => null
104
        };
105
    }
106
107
    public function getViewIdentifier(): string
108
    {
109
        return match ($this) {
110
            self::MENU_MAINSCREEN => ShowMainscreen::VIEW_IDENTIFIER,
111
            self::MENU_BUILD => ShowBuildMenu::VIEW_IDENTIFIER,
112
            self::MENU_INFO => ShowManagement::VIEW_IDENTIFIER,
113
            self::MENU_OPTION => ShowMisc::VIEW_IDENTIFIER,
114
            self::MENU_SOCIAL => ShowSocial::VIEW_IDENTIFIER,
115
            self::MENU_BUILDINGS => ShowBuildingManagement::VIEW_IDENTIFIER,
116
            self::MENU_AIRFIELD => ShowAirfield::VIEW_IDENTIFIER,
117
            self::MENU_MODULEFAB => ShowModuleFab::VIEW_IDENTIFIER,
118
            self::MENU_SHIPYARD => ShowShipyard::VIEW_IDENTIFIER,
119
            self::MENU_BUILDPLANS => ShowBuildPlans::VIEW_IDENTIFIER,
120
            self::MENU_FIGHTER_SHIPYARD => ShowFighterShipyard::VIEW_IDENTIFIER,
121
            self::MENU_TORPEDOFAB => ShowTorpedoFab::VIEW_IDENTIFIER,
122
            self::MENU_ACADEMY => ShowAcademy::VIEW_IDENTIFIER,
123
            self::MENU_WASTE => ShowWaste::VIEW_IDENTIFIER,
124
            self::MENU_FAB_HALL => ShowModuleFab::VIEW_IDENTIFIER,
125
            self::MENU_TECH_CENTER => ShowModuleFab::VIEW_IDENTIFIER,
126
            self::MENU_SUBSPACE_TELESCOPE => ShowSubspaceTelescope::VIEW_IDENTIFIER,
127
            self::MENU_SHIP_DISASSEMBLY => ShowShipDisassembly::VIEW_IDENTIFIER,
128
            self::MENU_SHIP_REPAIR => ShowShipRepair::VIEW_IDENTIFIER,
129
            self::MENU_SHIP_RETROFIT => ShowShipRetrofit::VIEW_IDENTIFIER
130
        };
131
    }
132
133 19
    public function getTemplate(): string
134
    {
135 19
        return match ($this) {
136 19
            self::MENU_MAINSCREEN => 'html/colony/menu/mainscreen.twig',
137 19
            self::MENU_BUILD => 'html/colony/menu/buildmenues.twig',
138 18
            self::MENU_INFO => 'html/colony/menu/management.twig',
139 14
            self::MENU_OPTION => 'html/colony/menu/miscellaneous.twig',
140 13
            self::MENU_SOCIAL => 'html/colony/menu/social.twig',
141 12
            self::MENU_BUILDINGS => 'html/colony/menu/buildingManagement.twig',
142 11
            self::MENU_AIRFIELD => 'html/colony/menu/airfield.twig',
143 10
            self::MENU_MODULEFAB => 'html/colony/menu/moduleFab.twig',
144 9
            self::MENU_SHIPYARD => 'html/colony/menu/shipyard.twig',
145 8
            self::MENU_BUILDPLANS => 'html/colony/menu/shipBuildplans.twig',
146 7
            self::MENU_FIGHTER_SHIPYARD => 'html/colony/menu/fighterShipyard.twig',
147 6
            self::MENU_TORPEDOFAB => 'html/colony/menu/torpedoFab.twig',
148 5
            self::MENU_ACADEMY => 'html/colony/menu/academy.twig',
149 4
            self::MENU_WASTE => 'html/colony/menu/waste.twig',
150 3
            self::MENU_FAB_HALL => 'html/colony/menu/componentFab.twig',
151 3
            self::MENU_TECH_CENTER => 'html/colony/menu/componentFab.twig',
152 3
            self::MENU_SUBSPACE_TELESCOPE => 'html/colony/menu/telescope.twig',
153 3
            self::MENU_SHIP_DISASSEMBLY => 'html/colony/menu/shipDisassembly.twig',
154 2
            self::MENU_SHIP_REPAIR => 'html/colony/menu/shipRepair.twig',
155 19
            self::MENU_SHIP_RETROFIT => 'html/colony/menu/shipRetrofit.twig'
156 19
        };
157
    }
158
159
    /** @return array<ColonyComponentEnum> */
160 18
    public function getNecessaryGuiComponents(): array
161
    {
162 18
        return match ($this) {
163
            // mainscreen
164 18
            self::MENU_MAINSCREEN => [
165 18
                ColonyComponentEnum::SURFACE,
166 18
                ColonyComponentEnum::SHIELDING,
167 18
                ColonyComponentEnum::EPS_BAR,
168 18
                ColonyComponentEnum::STORAGE,
169 18
                ColonyComponentEnum::MANAGEMENT,
170 18
                ColonyComponentEnum::EFFECTS
171 18
            ],
172
173
            // submenues
174 15
            self::MENU_BUILD => [ColonyComponentEnum::BUILD_MENUES],
175 14
            self::MENU_INFO => [ColonyComponentEnum::MANAGEMENT, ColonyComponentEnum::EFFECTS],
176 13
            self::MENU_OPTION => [],
177 12
            self::MENU_SOCIAL => [ColonyComponentEnum::SOCIAL],
178 11
            self::MENU_BUILDINGS => [ColonyComponentEnum::BUILDING_MANAGEMENT],
179
180
            // menues without surface
181 10
            self::MENU_AIRFIELD => [ColonyComponentEnum::AIRFIELD],
182 18
            self::MENU_MODULEFAB,
183 18
            self::MENU_FAB_HALL,
184 18
            self::MENU_TECH_CENTER,
185 9
            self::MENU_SHIPYARD => [ColonyComponentEnum::SHIPYARD],
186 8
            self::MENU_BUILDPLANS => [ColonyComponentEnum::SHIP_BUILDPLANS],
187 7
            self::MENU_FIGHTER_SHIPYARD => [ColonyComponentEnum::FIGHTER_SHIPYARD],
188 6
            self::MENU_TORPEDOFAB => [ColonyComponentEnum::TORPEDO_FAB],
189 5
            self::MENU_ACADEMY => [ColonyComponentEnum::ACADEMY],
190 4
            self::MENU_WASTE => [],
191 3
            self::MENU_SUBSPACE_TELESCOPE => [],
192 3
            self::MENU_SHIP_DISASSEMBLY => [ColonyComponentEnum::SHIP_DISASSEMBLY],
193 2
            self::MENU_SHIP_REPAIR => [ColonyComponentEnum::SHIP_REPAIR],
194 18
            self::MENU_SHIP_RETROFIT => [ColonyComponentEnum::SHIP_RETROFIT]
195 18
        };
196
    }
197
}
198