Test Failed
Pull Request — master (#1646)
by Nico
10:48
created

ShipNfsItem::getHoldingWebBackgroundStyle()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 4
nop 0
dl 0
loc 17
ccs 0
cts 8
cp 0
crap 30
rs 9.6111
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
14
final class ShipNfsItem
15
{
16
    private TShipItemInterface $item;
17
18
    private int $userId;
19
20
    public function __construct(
21
        TShipItemInterface $item,
22
        int $userId
23
    ) {
24
        $this->item = $item;
25
        $this->userId = $userId;
26
    }
27
28
    public function getId(): int
29
    {
30
        return $this->item->getShipId();
31
    }
32
    public function getFleetId(): ?int
33
    {
34
        return $this->item->getFleetId();
35
    }
36
    public function getName(): string
37
    {
38
        return $this->item->getShipName();
39
    }
40
    public function getHull(): int
41
    {
42
        return $this->item->getHull();
43
    }
44
    public function getMaxHull(): int
45
    {
46
        return $this->item->getMaxHull();
47
    }
48
    public function getShield(): int
49
    {
50
        return $this->item->getShield();
51
    }
52
    public function getShieldState(): bool
53
    {
54
        return $this->item->getShieldState() > ShipSystemModeEnum::MODE_OFF;
55
    }
56
    public function getCloakState(): bool
57
    {
58
59
        return $this->item->getCloakState() > ShipSystemModeEnum::MODE_OFF;
60
    }
61
    public function getWarpState(): bool
62
    {
63
        return $this->item->getWarpState() > ShipSystemModeEnum::MODE_OFF;
64
    }
65
    public function isTractorbeamPossible(): bool
66
    {
67
        return TractorBeamShipSystem::isTractorBeamPossible($this);
68
    }
69
    public function isInterceptable(): bool
70
    {
71
        return $this->getWarpState();
72
    }
73
    public function isDestroyed(): bool
74
    {
75
        return $this->item->isDestroyed();
76
    }
77
    public function isBase(): bool
78
    {
79
        return $this->item->getSpacecraftType() === SpacecraftTypeEnum::SPACECRAFT_TYPE_STATION;
80
    }
81
    public function isTrumfield(): bool
82
    {
83
        return $this->item->getRumpCategoryId() === ShipRumpEnum::SHIP_CATEGORY_DEBRISFIELD;;
84
    }
85
    public function isShuttle(): bool
86
    {
87
        return $this->item->getRumpCategoryId() === ShipRumpEnum::SHIP_CATEGORY_SHUTTLE;
88
    }
89
    public function getRumpId(): int
90
    {
91
        return $this->item->getRumpId();
92
    }
93
    public function getFormerRumpId(): ?int
94
    {
95
        return $this->item->getFormerRumpId();
96
    }
97
    public function getHoldingWebBackgroundStyle(): string
98
    {
99
        if ($this->item->getWebId() === null) {
100
            return '';
101
        }
102
103
        $finishTime = $this->item->getWebFinishTime();
104
105
        if ($finishTime === null || $finishTime < time()) {
106
            $icon =  'web.png';
107
        } else {
108
            $closeTofinish = $finishTime - time() < TimeConstants::ONE_HOUR_IN_SECONDS;
109
110
            $icon = $closeTofinish ? 'web_u.png' : 'web_u2.png';
111
        }
112
113
        return sprintf('background-image: url(assets/buttons/%s); vertical-align: middle; text-align: center;', $icon);
114
    }
115
    public function getRumpName(): string
116
    {
117
        return $this->item->getRumpName();
118
    }
119
    public function getUserId(): int
120
    {
121
        return $this->item->getUserId();
122
    }
123
124
    public function isContactable(): bool
125
    {
126
        return $this->getUserId() != UserEnum::USER_NOONE;
127
    }
128
129
    public function getUserName(): string
130
    {
131
        return $this->item->getUserName();
132
    }
133
    public function isOwnedByCurrentUser(): bool
134
    {
135
        return $this->userId === $this->getUserId();
136
    }
137
138
    public function hasUplink(): bool
139
    {
140
        return $this->item->getUplinkState() > ShipSystemModeEnum::MODE_OFF;
141
    }
142
143
    public function getRump(): mixed
144
    {
145
        return $this;
146
    }
147
148
    public function hasLogBook(): bool
149
    {
150
        return $this->item->hasLogBook();
151
    }
152
}
153