Passed
Push — dev ( c12b3a...6ad196 )
by Janko
24:31 queued 10:07
created

SpacecraftCrewTrait::getExcessCrewCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Stu\Component\Spacecraft\Trait;
4
5
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
6
use Stu\Module\Control\GameControllerInterface;
7
8
trait SpacecraftCrewTrait
9
{
10
    use SpacecraftTrait;
11
    use HasSpacecraftSystemTrait;
12
13 7
    public function getNeededCrewCount(): int
14
    {
15 7
        $buildplan = $this->getThis()->getBuildplan();
16 7
        if ($buildplan === null) {
17
            return 0;
18
        }
19
20 7
        return $buildplan->getCrew();
21
    }
22
23 12
    public function getCrewCount(): int
24
    {
25 12
        return $this->getThis()->getCrewAssignments()->count();
26
    }
27
28 6
    public function getExcessCrewCount(): int
29
    {
30 6
        return $this->getCrewCount() - $this->getNeededCrewCount();
31
    }
32
33 3
    public function hasEnoughCrew(?GameControllerInterface $game = null): bool
34
    {
35 3
        $buildplan = $this->getThis()->getBuildplan();
36
37 3
        if ($buildplan === null) {
38
            if ($game !== null) {
39
                $game->addInformation(_("Keine Crew vorhanden"));
40
            }
41
            return false;
42
        }
43
44 3
        $result = $buildplan->getCrew() <= 0
45 3
            || $this->getCrewCount() >= $buildplan->getCrew();
46
47 3
        if (!$result && $game !== null) {
48
            $game->addInformationf(
49
                _("Es werden %d Crewmitglieder benötigt"),
50
                $buildplan->getCrew()
51
            );
52
        }
53
54 3
        return $result;
55
    }
56
57
    public function canMan(): bool
58
    {
59
        $buildplan = $this->getThis()->getBuildplan();
60
61
        return $buildplan !== null
62
            && $buildplan->getCrew() > 0
63
            && $this->hasSpacecraftSystem(SpacecraftSystemTypeEnum::LIFE_SUPPORT);
64
    }
65
}
66