Test Failed
Push — dev ( d4c172...a63c79 )
by Janko
09:28
created

ManagerProviderStation::getEps()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\SpacecraftManagement\Provider;
6
7
use Doctrine\Common\Collections\Collection;
8
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...
9
use RuntimeException;
10
use Stu\Lib\Transfer\Storage\StorageManagerInterface;
11
use Stu\Module\Crew\Lib\CrewCreatorInterface;
12
use Stu\Module\Spacecraft\Lib\Crew\TroopTransferUtilityInterface;
13
use Stu\Module\Station\Lib\StationWrapperInterface;
14
use Stu\Orm\Entity\CommodityInterface;
15
use Stu\Orm\Entity\SpacecraftInterface;
16
use Stu\Orm\Entity\UserInterface;
17
18
class ManagerProviderStation implements ManagerProviderInterface
19
{
20
    public function __construct(
21
        private StationWrapperInterface $wrapper,
22
        private CrewCreatorInterface $crewCreator,
23
        private TroopTransferUtilityInterface $troopTransferUtility,
24
        private StorageManagerInterface $storageManager
25
    ) {}
26
27
    #[Override]
28
    public function getUser(): UserInterface
29
    {
30
        return $this->wrapper->get()->getUser();
31
    }
32
33
    #[Override]
34
    public function getEps(): int
35
    {
36
        $eps = $this->wrapper->getEpsSystemData();
37
38
        if ($eps === null) {
39
            return 0;
40
        }
41
42
        return $eps->getEps();
43
    }
44
45
    #[Override]
46
    public function lowerEps(int $amount): ManagerProviderInterface
47
    {
48
        $eps = $this->wrapper->getEpsSystemData();
49
50
        if ($eps === null) {
51
            throw new RuntimeException('can not lower eps without eps system');
52
        }
53
54
        $eps->lowerEps($amount)->update();
55
56
        return $this;
57
    }
58
59
    #[Override]
60
    public function getName(): string
61
    {
62
        $station = $this->wrapper->get();
63
64
        return sprintf(
65
            '%s %s',
66
            $station->getRump()->getName(),
67
            $station->getName(),
68
        );
69
    }
70
71
    #[Override]
72
    public function getSectorString(): string
73
    {
74
        return $this->wrapper->get()->getSectorString();
75
    }
76
77
    #[Override]
78
    public function getFreeCrewAmount(): int
79
    {
80
        return $this->wrapper->get()->getExcessCrewCount();
81
    }
82
83
    #[Override]
84
    public function addCrewAssignment(SpacecraftInterface $spacecraft, int $amount): void
85
    {
86
        $this->crewCreator->createCrewAssignment($spacecraft, $this->wrapper->get(), $amount);
87
    }
88
89
    #[Override]
90
    public function getFreeCrewStorage(): int
91
    {
92
        $station = $this->wrapper->get();
93
94
        return $this->troopTransferUtility->getFreeQuarters($station);
95
    }
96
97
    #[Override]
98
    public function addCrewAssignments(array $crewAssignments): void
99
    {
100
        $station = $this->wrapper->get();
101
102
        foreach ($crewAssignments as $crewAssignment) {
103
            $this->troopTransferUtility->assignCrew($crewAssignment, $station);
104
        }
105
    }
106
107
    #[Override]
108
    public function getStorage(): Collection
109
    {
110
        return $this->wrapper->get()->getStorage();
111
    }
112
113
    #[Override]
114
    public function upperStorage(CommodityInterface $commodity, int $amount): void
115
    {
116
        $this->storageManager->upperStorage(
117
            $this->wrapper->get(),
118
            $commodity,
119
            $amount
120
        );
121
    }
122
123
    #[Override]
124
    public function lowerStorage(CommodityInterface $commodity, int $amount): void
125
    {
126
        $this->storageManager->lowerStorage(
127
            $this->wrapper->get(),
128
            $commodity,
129
            $amount
130
        );
131
    }
132
}
133