Passed
Push — master ( 48bfaa...170129 )
by Nico
25:44
created

ShipNfsItem::getWarpDriveState()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib;
6
7
use Stu\Component\Game\TimeConstants;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Game\TimeConstants 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\Ship\ShipRumpEnum;
9
use Stu\Component\Ship\SpacecraftTypeEnum;
10
use Stu\Component\Ship\System\ShipSystemModeEnum;
11
use Stu\Component\Ship\System\Type\TractorBeamShipSystem;
12
use Stu\Module\PlayerSetting\Lib\UserEnum;
13
use Stu\Module\Ship\Lib\Battle\FightLib;
14
15
final class ShipNfsItem
16
{
17
    private TShipItemInterface $item;
18
19
    private int $userId;
20
21
    public function __construct(
22
        TShipItemInterface $item,
23
        int $userId
24
    ) {
25
        $this->item = $item;
26
        $this->userId = $userId;
27
    }
28
29
    public function getId(): int
30
    {
31
        return $this->item->getShipId();
32
    }
33
    public function getFleetId(): ?int
34
    {
35
        return $this->item->getFleetId();
36
    }
37
    public function getName(): string
38
    {
39
        return $this->item->getShipName();
40
    }
41
    public function getHull(): int
42
    {
43
        return $this->item->getHull();
44
    }
45
    public function getMaxHull(): int
46
    {
47
        return $this->item->getMaxHull();
48
    }
49
    public function getShield(): int
50
    {
51
        return $this->item->getShield();
52
    }
53
    public function getShieldState(): bool
54
    {
55
        return $this->item->getShieldState() > ShipSystemModeEnum::MODE_OFF;
56
    }
57
    public function getCloakState(): bool
58
    {
59
60
        return $this->item->getCloakState() > ShipSystemModeEnum::MODE_OFF;
61
    }
62
    public function getWarpDriveState(): bool
63
    {
64
        return $this->item->getWarpDriveState() > ShipSystemModeEnum::MODE_OFF;
65
    }
66
    public function isWarped(): bool
67
    {
68
        return $this->getWarpDriveState()
69
            || $this->item->getTractorWarpState() > ShipSystemModeEnum::MODE_OFF;
70
    }
71
    public function isTractorbeamPossible(): bool
72
    {
73
        return TractorBeamShipSystem::isTractorBeamPossible($this);
74
    }
75
    public function isBoardingPossible(): bool
76
    {
77
        return FightLib::isBoardingPossible($this);
78
    }
79
    public function isInterceptable(): bool
80
    {
81
        //TODO can tractored ships be intercepted?!
82
        return $this->getWarpDriveState();
83
    }
84
    public function isDestroyed(): bool
85
    {
86
        return $this->item->isDestroyed();
87
    }
88
    public function isBase(): bool
89
    {
90
        return $this->item->getSpacecraftType() === SpacecraftTypeEnum::SPACECRAFT_TYPE_STATION;
91
    }
92
    public function isTrumfield(): bool
93
    {
94
        return $this->item->getRumpCategoryId() === ShipRumpEnum::SHIP_CATEGORY_DEBRISFIELD;;
95
    }
96
    public function isShuttle(): bool
97
    {
98
        return $this->item->getRumpCategoryId() === ShipRumpEnum::SHIP_CATEGORY_SHUTTLE;
99
    }
100
    public function getRumpId(): int
101
    {
102
        return $this->item->getRumpId();
103
    }
104
    public function getFormerRumpId(): ?int
105
    {
106
        return $this->item->getFormerRumpId();
107
    }
108
    public function getHoldingWebBackgroundStyle(): string
109
    {
110
        if ($this->item->getWebId() === null) {
111
            return '';
112
        }
113
114
        $finishTime = $this->item->getWebFinishTime();
115
116
        if ($finishTime === null || $finishTime < time()) {
117
            $icon =  'web.png';
118
        } else {
119
            $closeTofinish = $finishTime - time() < TimeConstants::ONE_HOUR_IN_SECONDS;
120
121
            $icon = $closeTofinish ? 'web_u.png' : 'web_u2.png';
122
        }
123
124
        return sprintf('background-image: url(assets/buttons/%s); vertical-align: middle; text-align: center;', $icon);
125
    }
126
    public function getRumpName(): string
127
    {
128
        return $this->item->getRumpName();
129
    }
130
    public function getUserId(): int
131
    {
132
        return $this->item->getUserId();
133
    }
134
135
    public function isContactable(): bool
136
    {
137
        return $this->getUserId() != UserEnum::USER_NOONE;
138
    }
139
140
    public function getUserName(): string
141
    {
142
        return $this->item->getUserName();
143
    }
144
    public function isOwnedByCurrentUser(): bool
145
    {
146
        return $this->userId === $this->getUserId();
147
    }
148
149
    public function hasUplink(): bool
150
    {
151
        return $this->item->getUplinkState() > ShipSystemModeEnum::MODE_OFF;
152
    }
153
154
    public function getRump(): mixed
155
    {
156
        return $this;
157
    }
158
159
    public function hasLogBook(): bool
160
    {
161
        return $this->item->hasLogBook();
162
    }
163
164
    public function hasCrew(): bool
165
    {
166
        return $this->item->hasCrew();
167
    }
168
}
169