Passed
Push — master ( 0a21cd...0ad97c )
by Janko
05:01
created

ComputerSystemData::getEvadeChance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Spacecraft\System\Data;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Stu\Component\Map\DirectionEnum;
9
use Stu\Component\Spacecraft\SpacecraftAlertStateEnum;
10
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
11
12
class ComputerSystemData extends AbstractSystemData
13
{
14
    public int $hitChance = 0;
15
    public int $evadeChance = 0;
16
    public bool $isInEmergency = false;
17
    public DirectionEnum $flightDirection = DirectionEnum::NON;
18
    public SpacecraftAlertStateEnum $alertState = SpacecraftAlertStateEnum::ALERT_GREEN;
19
20 11
    #[Override]
21
    public function getSystemType(): SpacecraftSystemTypeEnum
22
    {
23 11
        return SpacecraftSystemTypeEnum::COMPUTER;
24
    }
25
26 2
    public function getHitChance(): int
27
    {
28 2
        return (int) (ceil($this->hitChance
29 2
            * $this->spacecraft->getSpacecraftSystem(SpacecraftSystemTypeEnum::COMPUTER)->getStatus() / 100));
30
    }
31
32 2
    public function setHitChance(int $hitChance): ComputerSystemData
33
    {
34 2
        $this->hitChance = $hitChance;
35 2
        return $this;
36
    }
37
38 2
    public function getEvadeChance(): int
39
    {
40 2
        if (!$this->spacecraft->hasSpacecraftSystem(SpacecraftSystemTypeEnum::IMPULSEDRIVE)) {
41 1
            return $this->evadeChance;
42
        }
43
44 1
        return (int) (ceil($this->evadeChance
45 1
            * $this->spacecraft->getSpacecraftSystem(SpacecraftSystemTypeEnum::IMPULSEDRIVE)->getStatus() / 100));
46
    }
47
48 2
    public function setEvadeChance(int $evadeChance): ComputerSystemData
49
    {
50 2
        $this->evadeChance = $evadeChance;
51 2
        return $this;
52
    }
53
54 3
    public function isInEmergency(): bool
55
    {
56 3
        return $this->isInEmergency;
57
    }
58
59
    public function setIsInEmergency(bool $isInEmergency): ComputerSystemData
60
    {
61
        $this->isInEmergency = $isInEmergency;
62
        return $this;
63
    }
64
65 1
    public function getFlightDirection(): DirectionEnum
66
    {
67 1
        return $this->flightDirection;
68
    }
69
70 3
    public function setFlightDirection(DirectionEnum $direction): ComputerSystemData
71
    {
72 3
        $this->flightDirection = $direction;
73 3
        return $this;
74
    }
75
76 19
    public function getAlertState(): SpacecraftAlertStateEnum
77
    {
78 19
        return $this->alertState;
79
    }
80
81 7
    public function setAlertState(SpacecraftAlertStateEnum $alertState): ComputerSystemData
82
    {
83 7
        $this->alertState = $alertState;
84 7
        return $this;
85
    }
86
87 6
    public function isAlertGreen(): bool
88
    {
89 6
        return $this->alertState === SpacecraftAlertStateEnum::ALERT_GREEN;
90
    }
91
92 1
    public function setAlertStateGreen(): ComputerSystemData
93
    {
94 1
        return $this->setAlertState(SpacecraftAlertStateEnum::ALERT_GREEN);
95
    }
96
}
97