Passed
Push — dev ( 98511f...00baf5 )
by Janko
15:17
created

SpacecraftStateTrait::isTractoring()   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\SpacecraftAlertStateEnum;
6
use Stu\Component\Spacecraft\SpacecraftStateEnum;
7
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
8
use Stu\Orm\Entity\SpacecraftInterface;
9
10
trait SpacecraftStateTrait
11
{
12
    use SpacecraftTrait;
13
    use SpacecraftSystemExistenceTrait;
14
15 2
    public function isWarped(): bool
16
    {
17 2
        return $this->getThis()->getWarpDriveState();
18
    }
19
20 1
    public function isAlertGreen(): bool
21
    {
22 1
        return $this->getThis()->getAlertState() === SpacecraftAlertStateEnum::ALERT_GREEN;
23
    }
24
25
    public function isUnderRepair(): bool
26
    {
27
        return $this->getThis()->getState() === SpacecraftStateEnum::REPAIR_ACTIVE
28
            || $this->getThis()->getState() === SpacecraftStateEnum::REPAIR_PASSIVE;
29
    }
30
31
    public function getHealthPercentage(): float
32
    {
33
        $self = $this->getThis();
34
        return ($self->getHull() + $self->getShield())
35
            / ($self->getMaxHull() + $self->getMaxShield(true)) * 100;
36
    }
37
38 1
    public function isTractoring(): bool
39
    {
40 1
        return $this->getThis()->getTractoredShip() !== null;
41
    }
42
43 1
    public function isWarpPossible(): bool
44
    {
45 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

45
        return $this->hasSpacecraftSystem(SpacecraftSystemTypeEnum::WARPDRIVE) && $this->/** @scrutinizer ignore-call */ getSystem() === null;
Loading history...
46
    }
47
48
    public function setAlertStateGreen(): SpacecraftInterface
49
    {
50
        return $this->getThis()->setAlertState(SpacecraftAlertStateEnum::ALERT_GREEN);
51
    }
52
53 1
    public function displayNbsActions(): bool
54
    {
55 1
        return !$this->getThis()->isCloaked()
56 1
            && !$this->getThis()->isWarped();
57
    }
58
}
59