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

SpacecraftStateTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 56.25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 37
ccs 9
cts 16
cp 0.5625
rs 10
c 1
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A displayNbsActions() 0 4 2
A isUnderRepair() 0 4 2
A getHealthPercentage() 0 5 1
A isWarpPossible() 0 3 2
A isWarped() 0 3 1
A isTractoring() 0 3 1
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