Passed
Push — dev ( eeaa0f...91a85a )
by Janko
26:10
created

LowerHull::lowerStationConstructionHull()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
nc 3
nop 0
dl 0
loc 19
ccs 0
cts 15
cp 0
crap 12
rs 9.8333
c 1
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Tick\Ship\ManagerComponent;
4
5
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...
6
use Stu\Lib\Information\InformationWrapper;
7
use Stu\Module\PlayerSetting\Lib\UserEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserEnum 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\Module\Ship\Lib\Destruction\ShipDestructionCauseEnum;
9
use Stu\Module\Ship\Lib\Destruction\ShipDestructionInterface;
10
use Stu\Module\Ship\Lib\ShipRemoverInterface;
11
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface;
12
use Stu\Orm\Repository\ShipRepositoryInterface;
13
use Stu\Orm\Repository\TradePostRepositoryInterface;
14
15
class LowerHull implements ManagerComponentInterface
16
{
17
    public function __construct(
18
        private ShipRemoverInterface $shipRemover,
19
        private ShipDestructionInterface $shipDestruction,
20
        private ShipRepositoryInterface $shipRepository,
21
        private TradePostRepositoryInterface $tradePostRepository,
22
        private ShipWrapperFactoryInterface $shipWrapperFactory
23
    ) {
24
    }
25
26
    #[Override]
27
    public function work(): void
28
    {
29
        $this->lowerTrumfieldHull();
30
        $this->lowerOrphanizedTradepostHull();
31
    }
32
33
    private function lowerTrumfieldHull(): void
34
    {
35
        foreach ($this->shipRepository->getDebrisFields() as $ship) {
36
            $lower = random_int(5, 15);
37
            if ($ship->getHull() <= $lower) {
38
                $this->shipRemover->remove($ship);
39
                continue;
40
            }
41
            $ship->setHull($ship->getHull() - $lower);
42
43
            $this->shipRepository->save($ship);
44
        }
45
    }
46
47
    private function lowerOrphanizedTradepostHull(): void
48
    {
49
        foreach ($this->tradePostRepository->getByUser(UserEnum::USER_NOONE) as $tradepost) {
50
            $ship = $tradepost->getShip();
51
52
            $lower = (int)ceil($ship->getMaxHull() / 100);
53
54
            if ($ship->getHull() <= $lower) {
55
                $this->shipDestruction->destroy(
56
                    null,
57
                    $this->shipWrapperFactory->wrapShip($ship),
58
                    ShipDestructionCauseEnum::ORPHANIZED_TRADEPOST,
59
                    new InformationWrapper()
60
                );
61
62
                continue;
63
            }
64
            $ship->setHull($ship->getHull() - $lower);
65
66
            $this->shipRepository->save($ship);
67
        }
68
    }
69
}
70