Failed Conditions
Push — dev ( 56c6e5...f96e05 )
by Janko
17:26
created

canTransferTorpedos()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Transfer\Wrapper;
6
7
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
8
use Stu\Lib\Information\InformationInterface;
9
use Stu\Orm\Entity\SpacecraftInterface;
10
use Stu\Orm\Entity\TorpedoTypeInterface;
11
12
class SpacecraftStorageTorpedoLogic
13
{
14
    public function canTransferTorpedos(SpacecraftInterface $spacecraft, InformationInterface $information): bool
15
    {
16
        if (!$spacecraft->isSystemHealthy(SpacecraftSystemTypeEnum::TORPEDO_STORAGE)) {
17
            $information->addInformation("Das Torpedolager ist zerstört");
18
            return false;
19
        }
20
21
        return true;
22
    }
23
24
    public function canStoreTorpedoType(SpacecraftInterface $spacecraft, TorpedoTypeInterface $torpedoType, InformationInterface $information): bool
25
    {
26
        if (
27
            !$spacecraft->isSystemHealthy(SpacecraftSystemTypeEnum::TORPEDO_STORAGE)
28
            && $spacecraft->getRump()->getTorpedoLevel() !== $torpedoType->getLevel()
29
        ) {
30
            $information->addInformationf('Die %s kann den Torpedotyp nicht ausrüsten', $spacecraft->getName());
31
            return false;
32
        }
33
34
        if (
35
            !$spacecraft->hasSpacecraftSystem(SpacecraftSystemTypeEnum::TORPEDO_STORAGE)
36
            && $torpedoType->getLevel() > $spacecraft->getRump()->getTorpedoLevel()
37
        ) {
38
            $information->addInformationf("Die %s kann den Torpedotyp nicht ausrüsten", $spacecraft->getName());
39
            return false;
40
        }
41
42
        if (
43
            $spacecraft->getTorpedo() !== null
44
            && $spacecraft->getTorpedo() !== $torpedoType
45
        ) {
46
            $information->addInformation("Es ist bereits ein anderer Torpedotyp geladen");
47
            return false;
48
        }
49
50
        return true;
51
    }
52
}
53