Passed
Pull Request — master (#1969)
by Janko
22:34 queued 10:03
created

ShipWrapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 10
dl 0
loc 22
ccs 11
cts 11
cp 1
crap 1
rs 9.9332
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib;
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\Spacecraft\Repair\RepairUtilInterface;
9
use Stu\Component\Spacecraft\SpacecraftAlertStateEnum;
10
use Stu\Component\Spacecraft\System\Data\AstroLaboratorySystemData;
11
use Stu\Component\Spacecraft\System\Data\BussardCollectorSystemData;
12
use Stu\Component\Spacecraft\System\Data\TrackerSystemData;
13
use Stu\Component\Spacecraft\System\Data\WebEmitterSystemData;
14
use Stu\Component\Spacecraft\System\SpacecraftSystemManagerInterface;
15
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
16
use Stu\Component\Spacecraft\System\SystemDataDeserializerInterface;
17
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface;
18
use Stu\Module\Control\GameControllerInterface;
19
use Stu\Module\Spacecraft\Lib\SpacecraftStateChangerInterface;
20
use Stu\Module\Spacecraft\Lib\Ui\StateIconAndTitle;
21
use Stu\Module\Spacecraft\Lib\SpacecraftWrapper;
22
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperFactoryInterface;
23
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
24
use Stu\Module\Station\Lib\StationWrapperInterface;
25
use Stu\Orm\Entity\ShipInterface;
26
use Stu\Orm\Repository\TorpedoTypeRepositoryInterface;
27
28
//TODO increase coverage
29
/**
30
 * @extends SpacecraftWrapper<ShipInterface>
31
 */
32
final class ShipWrapper extends SpacecraftWrapper implements ShipWrapperInterface
33
{
34 47
    public function __construct(
35
        ShipInterface $ship,
36
        SpacecraftSystemManagerInterface $spacecraftSystemManager,
37
        SystemDataDeserializerInterface $systemDataDeserializer,
38
        TorpedoTypeRepositoryInterface $torpedoTypeRepository,
39
        GameControllerInterface $game,
40
        SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory,
41
        SpacecraftStateChangerInterface $spacecraftStateChanger,
42
        RepairUtilInterface $repairUtil,
43
        StateIconAndTitle $stateIconAndTitle,
44
        private ColonyLibFactoryInterface $colonyLibFactory
45
    ) {
46 47
        parent::__construct(
47 47
            $ship,
48 47
            $spacecraftSystemManager,
49 47
            $systemDataDeserializer,
50 47
            $torpedoTypeRepository,
51 47
            $game,
52 47
            $spacecraftWrapperFactory,
53 47
            $spacecraftStateChanger,
54 47
            $repairUtil,
55 47
            $stateIconAndTitle
56 47
        );
57
    }
58
59 40
    public function get(): ShipInterface
60
    {
61 40
        return $this->spacecraft;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->spacecraft returns the type Stu\Orm\Entity\SpacecraftInterface which includes types incompatible with the type-hinted return Stu\Orm\Entity\ShipInterface.
Loading history...
62
    }
63
64
    #[Override]
65
    public function getFleetWrapper(): ?FleetWrapperInterface
66
    {
67
        $fleet = $this->get()->getFleet();
68
        if ($fleet === null) {
69
            return null;
70
        }
71
72
        return $this->spacecraftWrapperFactory->wrapFleet($fleet);
73
    }
74
75 7
    #[Override]
76
    public function canLandOnCurrentColony(): bool
77
    {
78 7
        if ($this->spacecraft->getRump()->getCommodity() === null) {
79 1
            return false;
80
        }
81 6
        if ($this->spacecraft->isShuttle()) {
82 1
            return false;
83
        }
84
85 5
        $currentColony = $this->spacecraft->getStarsystemMap() !== null ? $this->spacecraft->getStarsystemMap()->getColony() : null;
86
87 5
        if ($currentColony === null) {
88 2
            return false;
89
        }
90 3
        if ($currentColony->getUser() !== $this->spacecraft->getUser()) {
91 1
            return false;
92
        }
93
94 2
        return $this->colonyLibFactory
95 2
            ->createColonySurface($currentColony)
96 2
            ->hasAirfield();
97
    }
98
99
    #[Override]
100
    public function canBeRetrofitted(): bool
101
    {
102
        if ($this->spacecraft->getAlertState() !== SpacecraftAlertStateEnum::ALERT_GREEN) {
103
            return false;
104
        }
105
106
        if ($this->spacecraft->getFleet()) {
107
            return false;
108
        }
109
110
        if ($this->spacecraft->getShieldState()) {
111
            return false;
112
        }
113
114
        if ($this->spacecraft->getCloakState()) {
115
            return false;
116
        }
117
118
        if ($this->spacecraft->getUser() != $this->game->getUser()) {
119
            return false;
120
        }
121
122
        if (
123
            $this->spacecraft->getBuildplan() != null
124
            && $this->spacecraft->getBuildplan()->getUser() != $this->game->getUser()
125
        ) {
126
            return false;
127
        }
128
129
        return true;
130
    }
131
132
    #[Override]
133
    public function getTractoringSpacecraftWrapper(): ?SpacecraftWrapperInterface
134
    {
135
        $tractoringSpacecraft = $this->spacecraft->getTractoringSpacecraft();
0 ignored issues
show
Bug introduced by
The method getTractoringSpacecraft() does not exist on Stu\Orm\Entity\SpacecraftInterface. It seems like you code against a sub-type of Stu\Orm\Entity\SpacecraftInterface such as Stu\Orm\Entity\ShipInterface or Stu\Orm\Entity\Ship. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

135
        /** @scrutinizer ignore-call */ 
136
        $tractoringSpacecraft = $this->spacecraft->getTractoringSpacecraft();
Loading history...
136
        if ($tractoringSpacecraft === null) {
137
            return null;
138
        }
139
140
        return $this->spacecraftWrapperFactory->wrapSpacecraft($tractoringSpacecraft);
141
    }
142
143
    #[Override]
144
    public function getDockedToStationWrapper(): ?StationWrapperInterface
145
    {
146
        $dockedTo = $this->spacecraft->getDockedTo();
0 ignored issues
show
Bug introduced by
The method getDockedTo() does not exist on Stu\Orm\Entity\SpacecraftInterface. It seems like you code against a sub-type of Stu\Orm\Entity\SpacecraftInterface such as Stu\Orm\Entity\ShipInterface or Stu\Orm\Entity\Ship. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

146
        /** @scrutinizer ignore-call */ 
147
        $dockedTo = $this->spacecraft->getDockedTo();
Loading history...
147
        if ($dockedTo === null) {
148
            return null;
149
        }
150
151
        return $this->spacecraftWrapperFactory->wrapStation($dockedTo);
152
    }
153
154 1
    #[Override]
155
    public function getTrackerSystemData(): ?TrackerSystemData
156
    {
157 1
        return $this->getSpecificShipSystem(
158 1
            SpacecraftSystemTypeEnum::SYSTEM_TRACKER,
159 1
            TrackerSystemData::class
160 1
        );
161
    }
162
163
    #[Override]
164
    public function getBussardCollectorSystemData(): ?BussardCollectorSystemData
165
    {
166
        return $this->getSpecificShipSystem(
167
            SpacecraftSystemTypeEnum::SYSTEM_BUSSARD_COLLECTOR,
168
            BussardCollectorSystemData::class
169
        );
170
    }
171
172
    #[Override]
173
    public function getWebEmitterSystemData(): ?WebEmitterSystemData
174
    {
175
        return $this->getSpecificShipSystem(
176
            SpacecraftSystemTypeEnum::SYSTEM_THOLIAN_WEB,
177
            WebEmitterSystemData::class
178
        );
179
    }
180
181 3
    #[Override]
182
    public function getAstroLaboratorySystemData(): ?AstroLaboratorySystemData
183
    {
184 3
        return $this->getSpecificShipSystem(
185 3
            SpacecraftSystemTypeEnum::SYSTEM_ASTRO_LABORATORY,
186 3
            AstroLaboratorySystemData::class
187 3
        );
188
    }
189
}
190