Passed
Pull Request — master (#2138)
by Nico
25:02 queued 13:24
created

Station::getDockedShips()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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 1
    public function __construct()
57
    {
58 1
        parent::__construct();
59 1
        $this->dockedShips = new ArrayCollection();
60 1
        $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
    #[Override]
109
    public function resetConstructionProgress(): StationInterface
110
    {
111
        $this->constructionProgress = null;
112
113
        return $this;
114
    }
115
116 1
    #[Override]
117
    public function getModules(): array
118
    {
119 1
        $constructionProgress = $this->getConstructionProgress();
120 1
        if ($constructionProgress === null) {
121
            return [];
122
        }
123
124 1
        $parentModules = parent::getModules();
125 1
        $parentModuleIds = array_map(
126 1
            fn(ModuleInterface $module): int => $module->getId(),
127 1
            $parentModules
128 1
        );
129
130 1
        $specialModules = $constructionProgress
131 1
            ->getSpecialModules()
132 1
            ->filter(
133 1
                fn(ConstructionProgressModuleInterface $progressModule): bool =>
134 1
                !in_array($progressModule->getModule()->getId(), $parentModuleIds)
135 1
            )
136 1
            ->map(
137 1
                fn(ConstructionProgressModuleInterface $progressModule): ModuleInterface =>
138 1
                $progressModule->getModule()
139 1
            )
140 1
            ->toArray();
141
142 1
        return $parentModules + $specialModules;
143
    }
144
145
146 2
    #[Override]
147
    public function getDockPrivileges(): Collection
148
    {
149 2
        return $this->dockingPrivileges;
150
    }
151
152 1
    #[Override]
153
    public function getDockingSlotCount(): int
154
    {
155 1
        $state = $this->getCondition()->getState();
156
157 1
        return ($state === SpacecraftStateEnum::UNDER_CONSTRUCTION)
158 1
            || ($state === SpacecraftStateEnum::UNDER_SCRAPPING)
159 1
            ? 50 : $this->getRump()->getDockingSlots();
160
    }
161
162
    #[Override]
163
    public function hasFreeDockingSlots(): bool
164
    {
165
        return $this->getDockingSlotCount() > $this->getDockedShipCount();
166
    }
167
168
    #[Override]
169
    public function getFreeDockingSlotCount(): int
170
    {
171
        return $this->getDockingSlotCount() - $this->getDockedShipCount();
172
    }
173
174 2
    #[Override]
175
    public function getDockedShipCount(): int
176
    {
177 2
        return $this->dockedShips->count();
178
    }
179
180 3
    #[Override]
181
    public function getDockedShips(): Collection
182
    {
183 3
        return $this->dockedShips;
184
    }
185
186
    #[Override]
187
    public function getDockedWorkbeeCount(): int
188
    {
189
        $count = 0;
190
191
        foreach ($this->getDockedShips() as $ships) {
192
            if ($ships->getRump()->getCategoryId() === SpacecraftRumpEnum::SHIP_CATEGORY_SHUTTLE) {
193
                $count += 1;
194
            }
195
        }
196
197
        return $count;
198
    }
199
200
    #[Override]
201
    public function getConstructionHubState(): bool
202
    {
203
        return $this->getSystemState(SpacecraftSystemTypeEnum::CONSTRUCTION_HUB);
204
    }
205
206 1
    #[Override]
207
    public function isAggregationSystemHealthy(): bool
208
    {
209 1
        return $this->isSystemHealthy(SpacecraftSystemTypeEnum::AGGREGATION_SYSTEM);
210
    }
211
212 10
    #[Override]
213
    public function getTransferEntityType(): TransferEntityTypeEnum
214
    {
215 10
        return TransferEntityTypeEnum::STATION;
216
    }
217
}
218