Passed
Push — dev ( 231d4b...6ea563 )
by Janko
101:30 queued 71:11
created

ShipNfsItem::hasUplink()   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 ShipNfsItem
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 isTractorbeamPossible(): bool
63
    {
64 1
        return TractorBeamShipSystem::isTractorBeamPossible($this);
65
    }
66 1
    public function isBoardingPossible(): bool
67
    {
68 1
        return FightLib::isBoardingPossible($this);
69
    }
70 1
    public function isInterceptable(): bool
71
    {
72
        //TODO can tractored ships be intercepted?!
73 1
        return $this->getWarpDriveState();
74
    }
75 1
    public function getType(): SpacecraftTypeEnum
76
    {
77 1
        return $this->item->getType();
78
    }
79 1
    public function isStation(): bool
80
    {
81 1
        return $this->item->getType() === SpacecraftTypeEnum::STATION;
82
    }
83 1
    public function isTrumfield(): bool
84
    {
85 1
        return false;
86
    }
87 1
    public function isShuttle(): bool
88
    {
89 1
        return $this->item->getRumpCategoryId() === SpacecraftRumpEnum::SHIP_CATEGORY_SHUTTLE;
90
    }
91 1
    public function getRumpId(): int
92
    {
93 1
        return $this->item->getRumpId();
94
    }
95 1
    public function getHoldingWebBackgroundStyle(): string
96
    {
97 1
        if ($this->item->getWebId() === null) {
98 1
            return '';
99
        }
100
101
        $finishTime = $this->item->getWebFinishTime();
102
103
        if ($finishTime === null || $finishTime < time()) {
104
            $icon =  'web.png';
105
        } else {
106
            $closeTofinish = $finishTime - time() < TimeConstants::ONE_HOUR_IN_SECONDS;
107
108
            $icon = $closeTofinish ? 'web_u.png' : 'web_u2.png';
109
        }
110
111
        return sprintf('background-image: url(assets/buttons/%s); vertical-align: middle; text-align: center;', $icon);
112
    }
113 1
    public function getRumpName(): string
114
    {
115 1
        return $this->item->getRumpName();
116
    }
117 1
    public function getUserId(): int
118
    {
119 1
        return $this->item->getUserId();
120
    }
121
122 1
    public function isContactable(): bool
123
    {
124 1
        return $this->getUserId() != UserEnum::USER_NOONE;
125
    }
126
127 1
    public function getUserName(): string
128
    {
129 1
        return $this->item->getUserName();
130
    }
131 1
    public function isSelectable(): bool
132
    {
133 1
        return $this->userId === $this->getUserId()
134 1
            && $this->getType()->getModuleView() !== null;
135
    }
136
137
    public function hasUplink(): bool
138
    {
139
        return $this->item->getUplinkState() > SpacecraftSystemModeEnum::MODE_OFF->value;
140
    }
141
142
    public function getRump(): mixed
143
    {
144
        return $this;
145
    }
146
147 1
    public function hasLogBook(): bool
148
    {
149 1
        return $this->item->hasLogBook();
150
    }
151
152 1
    public function hasCrew(): bool
153
    {
154 1
        return $this->item->hasCrew();
155
    }
156
157 1
    public function getTransferEntityType(): TransferEntityTypeEnum
158
    {
159 1
        return $this->isStation()
160 1
            ? TransferEntityTypeEnum::STATION
161 1
            : TransferEntityTypeEnum::SHIP;
162
    }
163
}
164