Passed
Push — dev ( b3b4f7...388566 )
by Nico
15:02
created

Station::getModules()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 2.0004

Importance

Changes 0
Metric Value
cc 2
eloc 18
nc 2
nop 0
dl 0
loc 27
ccs 20
cts 21
cp 0.9524
crap 2.0004
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping\Column;
10
use Doctrine\ORM\Mapping\Entity;
11
use Doctrine\ORM\Mapping\Index;
12
use Doctrine\ORM\Mapping\JoinColumn;
13
use Doctrine\ORM\Mapping\OneToMany;
14
use Doctrine\ORM\Mapping\OneToOne;
15
use Doctrine\ORM\Mapping\OrderBy;
16
use Doctrine\ORM\Mapping\Table;
17
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...
18
use Stu\Component\Spacecraft\SpacecraftRumpEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Spacecraft\SpacecraftRumpEnum 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...
19
use Stu\Component\Spacecraft\SpacecraftStateEnum;
20
use Stu\Component\Spacecraft\SpacecraftTypeEnum;
21
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
22
use Stu\Lib\Transfer\TransferEntityTypeEnum;
23
use Stu\Orm\Repository\StationRepository;
24
25
#[Table(name: 'stu_station')]
26
#[Index(name: 'station_influence_area_idx', columns: ['influence_area_id'])]
27
#[Entity(repositoryClass: StationRepository::class)]
28
class Station extends Spacecraft implements StationInterface
29
{
30
    #[Column(type: 'integer', nullable: true)]
31
    private ?int $influence_area_id = null;
0 ignored issues
show
introduced by
The private property $influence_area_id is not used, and could be removed.
Loading history...
32
33
    #[OneToOne(targetEntity: 'TradePost', mappedBy: 'station')]
34
    private ?TradePostInterface $tradePost = null;
35
36
    #[OneToOne(targetEntity: 'ConstructionProgress', mappedBy: 'station')]
37
    private ?ConstructionProgressInterface $constructionProgress = null;
38
39
    /**
40
     * @var ArrayCollection<int, ShipInterface>
41
     */
42
    #[OneToMany(targetEntity: 'Ship', mappedBy: 'dockedTo', indexBy: 'id')]
43
    #[OrderBy(['fleet_id' => 'DESC', 'is_fleet_leader' => 'DESC'])]
44
    private Collection $dockedShips;
45
46
    /**
47
     * @var ArrayCollection<int, DockingPrivilegeInterface>
48
     */
49
    #[OneToMany(targetEntity: 'DockingPrivilege', mappedBy: 'station')]
50
    private Collection $dockingPrivileges;
51
52
    #[OneToOne(targetEntity: 'StarSystem')]
53
    #[JoinColumn(name: 'influence_area_id', referencedColumnName: 'id')]
54
    private ?StarSystemInterface $influenceArea = null;
55
56
    public function __construct()
57
    {
58
        parent::__construct();
59
        $this->dockedShips = new ArrayCollection();
60
        $this->dockingPrivileges = new ArrayCollection();
61
    }
62
63 3
    #[Override]
64
    public function getType(): SpacecraftTypeEnum
65
    {
66 3
        return SpacecraftTypeEnum::STATION;
67
    }
68
69 2
    #[Override]
70
    public function getFleet(): ?FleetInterface
71
    {
72 2
        return null;
73
    }
74
75 3
    #[Override]
76
    public function getTradePost(): ?TradePostInterface
77
    {
78 3
        return $this->tradePost;
79
    }
80
81
    #[Override]
82
    public function setTradePost(?TradePostInterface $tradePost): StationInterface
83
    {
84
        $this->tradePost = $tradePost;
85
86
        return $this;
87
    }
88
89
    #[Override]
90
    public function getInfluenceArea(): ?StarSystemInterface
91
    {
92
        return $this->influenceArea;
93
    }
94
95
    #[Override]
96
    public function setInfluenceArea(?StarSystemInterface $influenceArea): StationInterface
97
    {
98
        $this->influenceArea = $influenceArea;
99
        return $this;
100
    }
101
102 1
    #[Override]
103
    public function getConstructionProgress(): ?ConstructionProgressInterface
104
    {
105 1
        return $this->constructionProgress;
106
    }
107
108 1
    #[Override]
109
    public function getModules(): array
110
    {
111 1
        $constructionProgress = $this->getConstructionProgress();
112 1
        if ($constructionProgress === null) {
113
            return [];
114
        }
115
116 1
        $parentModules = parent::getModules();
117 1
        $parentModuleIds = array_map(
118 1
            fn(ModuleInterface $module): int => $module->getId(),
119 1
            $parentModules
120 1
        );
121
122 1
        $specialModules = $constructionProgress
123 1
            ->getSpecialModules()
124 1
            ->filter(
125 1
                fn(ConstructionProgressModuleInterface $progressModule): bool =>
126 1
                !in_array($progressModule->getModule()->getId(), $parentModuleIds)
127 1
            )
128 1
            ->map(
129 1
                fn(ConstructionProgressModuleInterface $progressModule): ModuleInterface =>
130 1
                $progressModule->getModule()
131 1
            )
132 1
            ->toArray();
133
134 1
        return $parentModules + $specialModules;
135
    }
136
137
138 2
    #[Override]
139
    public function getDockPrivileges(): Collection
140
    {
141 2
        return $this->dockingPrivileges;
142
    }
143
144 1
    #[Override]
145
    public function getDockingSlotCount(): int
146
    {
147 1
        return ($this->getState() === SpacecraftStateEnum::UNDER_CONSTRUCTION)
148 1
            || ($this->getState() === SpacecraftStateEnum::UNDER_SCRAPPING)
149 1
            ? 50 : $this->getRump()->getDockingSlots();
150
    }
151
152
    #[Override]
153
    public function hasFreeDockingSlots(): bool
154
    {
155
        return $this->getDockingSlotCount() > $this->getDockedShipCount();
156
    }
157
158
    #[Override]
159
    public function getFreeDockingSlotCount(): int
160
    {
161
        return $this->getDockingSlotCount() - $this->getDockedShipCount();
162
    }
163
164 2
    #[Override]
165
    public function getDockedShipCount(): int
166
    {
167 2
        return $this->dockedShips->count();
168
    }
169
170 3
    #[Override]
171
    public function getDockedShips(): Collection
172
    {
173 3
        return $this->dockedShips;
174
    }
175
176
    #[Override]
177
    public function getDockedWorkbeeCount(): int
178
    {
179
        $count = 0;
180
181
        foreach ($this->getDockedShips() as $ships) {
182
            if ($ships->getRump()->getCategoryId() === SpacecraftRumpEnum::SHIP_CATEGORY_SHUTTLE) {
183
                $count += 1;
184
            }
185
        }
186
187
        return $count;
188
    }
189
190
    #[Override]
191
    public function getConstructionHubState(): bool
192
    {
193
        return $this->getSystemState(SpacecraftSystemTypeEnum::CONSTRUCTION_HUB);
194
    }
195
196 1
    #[Override]
197
    public function isAggregationSystemHealthy(): bool
198
    {
199 1
        return $this->isSystemHealthy(SpacecraftSystemTypeEnum::AGGREGATION_SYSTEM);
200
    }
201
202 10
    #[Override]
203
    public function getTransferEntityType(): TransferEntityTypeEnum
204
    {
205 10
        return TransferEntityTypeEnum::STATION;
206
    }
207
}