Passed
Branch master (89bdb5)
by Janko
11:58
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\System\Data\AstroLaboratorySystemData;
9
use Stu\Component\Spacecraft\System\Data\BussardCollectorSystemData;
10
use Stu\Component\Spacecraft\System\Data\TrackerSystemData;
11
use Stu\Component\Spacecraft\System\Data\WebEmitterSystemData;
12
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
13
use Stu\Module\Spacecraft\Lib\SpacecraftWrapper;
14
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
15
use Stu\Module\Station\Lib\StationWrapperInterface;
16
use Stu\Orm\Entity\ShipInterface;
17
18
//TODO increase coverage
19
/**
20
 * @extends SpacecraftWrapper<ShipInterface>
21
 */
22
final class ShipWrapper extends SpacecraftWrapper implements ShipWrapperInterface
23
{
24 45
    #[Override]
25
    public function get(): ShipInterface
26
    {
27 45
        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...
28
    }
29
30
    #[Override]
31
    public function getFleetWrapper(): ?FleetWrapperInterface
32
    {
33
        $fleet = $this->spacecraft->getFleet();
34
        if ($fleet === null) {
35
            return null;
36
        }
37
38
        return $this->spacecraftWrapperFactory->wrapFleet($fleet);
39
    }
40
41 7
    #[Override]
42
    public function canLandOnCurrentColony(): bool
43
    {
44 7
        if ($this->spacecraft->getRump()->getCommodity() === null) {
45 1
            return false;
46
        }
47 6
        if ($this->spacecraft->isShuttle()) {
48 1
            return false;
49
        }
50
51 5
        $currentColony = $this->spacecraft->getStarsystemMap() !== null ? $this->spacecraft->getStarsystemMap()->getColony() : null;
52
53 5
        if ($currentColony === null) {
54 2
            return false;
55
        }
56 3
        if ($currentColony->getUser() !== $this->spacecraft->getUser()) {
57 1
            return false;
58
        }
59
60 2
        return $this->colonyLibFactory
61 2
            ->createColonySurface($currentColony)
62 2
            ->hasAirfield();
63
    }
64
65
    #[Override]
66
    public function canBeRetrofitted(): bool
67
    {
68
        if (!$this->isUnalerted()) {
69
            return false;
70
        }
71
72
        if ($this->spacecraft->getFleet() !== null) {
73
            return false;
74
        }
75
76
        if ($this->spacecraft->isShielded()) {
77
            return false;
78
        }
79
80
        if ($this->spacecraft->isCloaked()) {
81
            return false;
82
        }
83
84
        if ($this->spacecraft->getUser() != $this->game->getUser()) {
85
            return false;
86
        }
87
88
        if (
89
            $this->spacecraft->getBuildplan() != null
90
            && $this->spacecraft->getBuildplan()->getUser() != $this->game->getUser()
91
        ) {
92
            return false;
93
        }
94
95
        return true;
96
    }
97
98
    #[Override]
99
    public function getTractoringSpacecraftWrapper(): ?SpacecraftWrapperInterface
100
    {
101
        $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

101
        /** @scrutinizer ignore-call */ 
102
        $tractoringSpacecraft = $this->spacecraft->getTractoringSpacecraft();
Loading history...
102
        if ($tractoringSpacecraft === null) {
103
            return null;
104
        }
105
106
        return $this->spacecraftWrapperFactory->wrapSpacecraft($tractoringSpacecraft);
107
    }
108
109
    #[Override]
110
    public function getDockedToStationWrapper(): ?StationWrapperInterface
111
    {
112
        $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

112
        /** @scrutinizer ignore-call */ 
113
        $dockedTo = $this->spacecraft->getDockedTo();
Loading history...
113
        if ($dockedTo === null) {
114
            return null;
115
        }
116
117
        return $this->spacecraftWrapperFactory->wrapStation($dockedTo);
118
    }
119
120 1
    #[Override]
121
    public function getTrackerSystemData(): ?TrackerSystemData
122
    {
123 1
        return $this->getSpecificShipSystem(
124 1
            SpacecraftSystemTypeEnum::TRACKER,
125 1
            TrackerSystemData::class
126 1
        );
127
    }
128
129 1
    #[Override]
130
    public function getBussardCollectorSystemData(): ?BussardCollectorSystemData
131
    {
132 1
        return $this->getSpecificShipSystem(
133 1
            SpacecraftSystemTypeEnum::BUSSARD_COLLECTOR,
134 1
            BussardCollectorSystemData::class
135 1
        );
136
    }
137
138 1
    #[Override]
139
    public function getWebEmitterSystemData(): ?WebEmitterSystemData
140
    {
141 1
        return $this->getSpecificShipSystem(
142 1
            SpacecraftSystemTypeEnum::THOLIAN_WEB,
143 1
            WebEmitterSystemData::class
144 1
        );
145
    }
146
147
    #[Override]
148
    public function getAstroLaboratorySystemData(): ?AstroLaboratorySystemData
149
    {
150
        return $this->getSpecificShipSystem(
151
            SpacecraftSystemTypeEnum::ASTRO_LABORATORY,
152
            AstroLaboratorySystemData::class
153
        );
154
    }
155
}
156