Passed
Push — dev ( f29cfd...d7eff6 )
by Janko
11:00
created

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