Passed
Push — dev ( 3fd410...aa33df )
by Janko
13:32
created

SpacecraftStateTrait::setAlertStateGreen()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

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 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Stu\Component\Spacecraft\Trait;
4
5
use Stu\Component\Spacecraft\SpacecraftStateEnum;
6
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
7
8
trait SpacecraftStateTrait
9
{
10
    use SpacecraftTrait;
11
    use SpacecraftSystemExistenceTrait;
12
13 2
    public function isWarped(): bool
14
    {
15 2
        return $this->getThis()->getWarpDriveState();
16
    }
17
18
    public function isUnderRepair(): bool
19
    {
20
        return $this->getThis()->getState() === SpacecraftStateEnum::REPAIR_ACTIVE
21
            || $this->getThis()->getState() === SpacecraftStateEnum::REPAIR_PASSIVE;
22
    }
23
24
    public function getHealthPercentage(): float
25
    {
26
        $self = $this->getThis();
27
        return ($self->getHull() + $self->getShield())
28
            / ($self->getMaxHull() + $self->getMaxShield(true)) * 100;
29
    }
30
31 1
    public function isTractoring(): bool
32
    {
33 1
        return $this->getThis()->getTractoredShip() !== null;
34
    }
35
36 1
    public function isWarpPossible(): bool
37
    {
38 1
        return $this->hasSpacecraftSystem(SpacecraftSystemTypeEnum::WARPDRIVE) && $this->getSystem() === null;
0 ignored issues
show
Bug introduced by
It seems like getSystem() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        return $this->hasSpacecraftSystem(SpacecraftSystemTypeEnum::WARPDRIVE) && $this->/** @scrutinizer ignore-call */ getSystem() === null;
Loading history...
39
    }
40
41 1
    public function displayNbsActions(): bool
42
    {
43 1
        return !$this->getThis()->isCloaked()
44 1
            && !$this->getThis()->isWarped();
45
    }
46
}
47