Skip to content

Commit 46d61ba

Browse files
committed
code optimization
1 parent 245a0d4 commit 46d61ba

File tree

10 files changed

+31
-51
lines changed

10 files changed

+31
-51
lines changed

src/Lib/Colony/PlanetFieldHostInterface.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ public function getMaxEps(): int;
3030

3131
public function getMaxStorage(): int;
3232

33-
public function getPlanetFieldHostIdentifier(): string;
34-
35-
public function getPlanetFieldHostColumnIdentifier(): string;
36-
3733
public function getColonyClass(): ColonyClassInterface;
3834

3935
/**

src/Lib/Colony/PlanetFieldHostTypeEnum.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,20 @@ enum PlanetFieldHostTypeEnum: int
88
{
99
case COLONY = 1;
1010
case SANDBOX = 2;
11+
12+
public function getPlanetFieldHostIdentifier(): string
13+
{
14+
return match ($this) {
15+
self::COLONY => 'colony',
16+
self::SANDBOX => 'sandbox',
17+
};
18+
}
19+
20+
public function getPlanetFieldHostColumnIdentifier(): string
21+
{
22+
return match ($this) {
23+
self::COLONY => 'colonies_id',
24+
self::SANDBOX => 'colony_sandbox_id'
25+
};
26+
}
1127
}

src/Module/Colony/Action/LandShip/LandShip.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function handle(GameControllerInterface $game): void
5252
) {
5353
return;
5454
}
55-
if (!$colony->storagePlaceLeft()) {
55+
if ($colony->getMaxStorage() <= $colony->getStorageSum()) {
5656
$game->addInformation(_('Kein Lagerraum verfügbar'));
5757
return;
5858
}

src/Orm/Entity/Colony.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,6 @@ public function getStorageSum(): int
263263
);
264264
}
265265

266-
#[Override]
267-
public function storagePlaceLeft(): bool
268-
{
269-
return $this->getMaxStorage() > $this->getStorageSum();
270-
}
271-
272266
#[Override]
273267
public function getStarsystemMap(): StarSystemMapInterface
274268
{
@@ -420,18 +414,6 @@ public function getSectorString(): string
420414
return $this->getStarsystemMap()->getSectorString();
421415
}
422416

423-
#[Override]
424-
public function getPlanetFieldHostIdentifier(): string
425-
{
426-
return 'colony';
427-
}
428-
429-
#[Override]
430-
public function getPlanetFieldHostColumnIdentifier(): string
431-
{
432-
return 'colonies_id';
433-
}
434-
435417
#[Override]
436418
public function isColony(): bool
437419
{

src/Orm/Entity/ColonyInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ public function setSurfaceWidth(int $surfaceWidth): ColonyInterface;
5858

5959
public function setColonyClass(ColonyClassInterface $colonyClass): ColonyInterface;
6060

61-
public function storagePlaceLeft(): bool;
62-
6361
public function getStarsystemMap(): StarSystemMapInterface;
6462

6563
public function setStarsystemMap(StarSystemMapInterface $systemMap): ColonyInterface;

src/Orm/Entity/ColonySandbox.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,6 @@ public function getColonyClass(): ColonyClassInterface
202202
return $this->getColony()->getColonyClass();
203203
}
204204

205-
#[Override]
206-
public function getPlanetFieldHostIdentifier(): string
207-
{
208-
return 'sandbox';
209-
}
210-
211-
#[Override]
212-
public function getPlanetFieldHostColumnIdentifier(): string
213-
{
214-
return 'colony_sandbox_id';
215-
}
216-
217205
#[Override]
218206
public function isColony(): bool
219207
{

src/Orm/Repository/BuildingCommodityRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getProductionByColony(PlanetFieldHostInterface $host, ColonyClas
4646
WHERE c.count != 0 OR d.count != 0
4747
GROUP BY a.id
4848
ORDER BY a.sort ASC',
49-
$host->getPlanetFieldHostColumnIdentifier()
49+
$host->getHostType()->getPlanetFieldHostColumnIdentifier()
5050
),
5151
$rsm
5252
)

src/Orm/Repository/BuildingRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function getBuildmenuBuildings(
6767
Researched::class,
6868
PlanetFieldTypeBuilding::class,
6969
PlanetField::class,
70-
$host->getPlanetFieldHostColumnIdentifier(),
70+
$host->getHostType()->getPlanetFieldHostColumnIdentifier(),
7171
ColonyClassRestriction::class,
7272
$commodityFilter,
7373
$fieldTypeFilter

src/Orm/Repository/CommodityRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getByBuildingsOnColony(PlanetFieldHostInterface $host): array
3636
Commodity::class,
3737
BuildingCommodity::class,
3838
PlanetField::class,
39-
$host->getPlanetFieldHostColumnIdentifier()
39+
$host->getHostType()->getPlanetFieldHostColumnIdentifier()
4040
)
4141
)
4242
->setParameter('hostId', $host->getId())

src/Orm/Repository/PlanetFieldRepository.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getEnergyConsumingByHost(
9090
SELECT b.id FROM %s b WHERE b.eps_proc < 0
9191
)',
9292
PlanetField::class,
93-
$host->getPlanetFieldHostColumnIdentifier(),
93+
$host->getHostType()->getPlanetFieldHostColumnIdentifier(),
9494
Building::class
9595
)
9696
)->setParameters([
@@ -112,7 +112,7 @@ public function getEnergyProducingByHost(PlanetFieldHostInterface $host): array
112112
SELECT b.id FROM %s b WHERE b.eps_proc > 0
113113
)',
114114
PlanetField::class,
115-
$host->getPlanetFieldHostColumnIdentifier(),
115+
$host->getHostType()->getPlanetFieldHostColumnIdentifier(),
116116
Building::class
117117
)
118118
)->setParameters([
@@ -130,7 +130,7 @@ public function getHousingProvidingByHost(PlanetFieldHostInterface $host): array
130130
SELECT b.id FROM %s b WHERE b.bev_pro > 0
131131
)',
132132
PlanetField::class,
133-
$host->getPlanetFieldHostColumnIdentifier(),
133+
$host->getHostType()->getPlanetFieldHostColumnIdentifier(),
134134
Building::class
135135
)
136136
)->setParameters([
@@ -148,7 +148,7 @@ public function getWorkerConsumingByHost(PlanetFieldHostInterface $host): array
148148
SELECT b.id FROM %s b WHERE b.bev_use > 0
149149
)',
150150
PlanetField::class,
151-
$host->getPlanetFieldHostColumnIdentifier(),
151+
$host->getHostType()->getPlanetFieldHostColumnIdentifier(),
152152
Building::class
153153
)
154154
)->setParameters([
@@ -201,7 +201,7 @@ public function getCommodityConsumingByHostAndCommodity(
201201
SELECT bg.buildings_id FROM %s bg WHERE bg.commodity_id = :commodityId AND bg.count < 0
202202
) AND f.aktiv IN (:state)',
203203
PlanetField::class,
204-
$host->getPlanetFieldHostColumnIdentifier(),
204+
$host->getHostType()->getPlanetFieldHostColumnIdentifier(),
205205
BuildingCommodity::class
206206
)
207207
)->setParameters([
@@ -224,7 +224,7 @@ public function getCommodityProducingByHostAndCommodity(PlanetFieldHostInterface
224224
SELECT bg.buildings_id FROM %s bg WHERE bg.commodity_id = :commodityId AND bg.count > 0
225225
)',
226226
PlanetField::class,
227-
$host->getPlanetFieldHostColumnIdentifier(),
227+
$host->getHostType()->getPlanetFieldHostColumnIdentifier(),
228228
BuildingCommodity::class
229229
)
230230
)->setParameters([
@@ -237,7 +237,7 @@ public function getCommodityProducingByHostAndCommodity(PlanetFieldHostInterface
237237
public function getCountByHostAndBuilding(PlanetFieldHostInterface $host, int $buildingId): int
238238
{
239239
return $this->count([
240-
$host->getPlanetFieldHostColumnIdentifier() => $host->getId(),
240+
$host->getHostType()->getPlanetFieldHostColumnIdentifier() => $host->getId(),
241241
'buildings_id' => $buildingId,
242242
]);
243243
}
@@ -275,7 +275,7 @@ public function getCountByColonyAndBuildingFunctionAndState(
275275
SELECT bf.buildings_id FROM %s bf WHERE bf.function IN (:buildingFunctionIds)
276276
)',
277277
PlanetField::class,
278-
$host->getPlanetFieldHostIdentifier(),
278+
$host->getHostType()->getPlanetFieldHostIdentifier(),
279279
BuildingFunction::class
280280
)
281281
)->setParameters([
@@ -326,7 +326,7 @@ public function getMaxShieldsOfHost(PlanetFieldHostInterface $host): int
326326
WHERE f1.%s = :hostId AND f1.aktiv = 1 AND f1.buildings_id IN (
327327
SELECT bf1.buildings_id FROM stu_buildings_functions bf1 WHERE bf1.function = :shieldGenerator
328328
)',
329-
$host->getPlanetFieldHostColumnIdentifier()
329+
$host->getHostType()->getPlanetFieldHostColumnIdentifier()
330330
),
331331
$rsm
332332
)->setParameters([
@@ -380,7 +380,7 @@ public function getByColonyWithBuilding(PlanetFieldHostInterface $host): array
380380
ORDER BY b.name ASC',
381381
PlanetField::class,
382382
Building::class,
383-
$host->getPlanetFieldHostColumnIdentifier(),
383+
$host->getHostType()->getPlanetFieldHostColumnIdentifier(),
384384
)
385385
)->setParameters([
386386
'hostId' => $host->getId(),
@@ -402,7 +402,7 @@ public function getEnergyProductionByHost(
402402
AND cfd.%s = :host',
403403
PlanetField::class,
404404
Building::class,
405-
$host->getPlanetFieldHostIdentifier()
405+
$host->getHostType()->getPlanetFieldHostIdentifier()
406406
)
407407
)->setParameters([
408408
'state' => 1,

0 commit comments

Comments
 (0)