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

SpacecraftStorageTorpedoLogic   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 39
ccs 0
cts 19
cp 0
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
B canStoreTorpedoType() 0 27 7
A canTransferTorpedos() 0 8 2
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