Passed
Push — dev ( 3fd410...aa33df )
by Janko
13:32
created

ShipSystemDataFactory::createSystemData()   C

Complexity

Conditions 17
Paths 17

Size

Total Lines 92
Code Lines 70

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 62
CRAP Score 22.7262

Importance

Changes 0
Metric Value
cc 17
eloc 70
nc 17
nop 2
dl 0
loc 92
ccs 62
cts 85
cp 0.7294
crap 22.7262
rs 5.2166
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Spacecraft\System\Data;
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\Exception\InvalidSystemException;
9
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
10
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperFactoryInterface;
11
use Stu\Module\Template\StatusBarFactoryInterface;
12
use Stu\Orm\Repository\ShipRepositoryInterface;
13
use Stu\Orm\Repository\SpacecraftSystemRepositoryInterface;
14
use Stu\Orm\Repository\TholianWebRepositoryInterface;
15
16
final class ShipSystemDataFactory implements ShipSystemDataFactoryInterface
17
{
18 1
    public function __construct(
19
        private ShipRepositoryInterface $shipRepository,
20
        private SpacecraftSystemRepositoryInterface $shipSystemRepository,
21
        private TholianWebRepositoryInterface $tholianWebRepository,
22
        private StatusBarFactoryInterface $statusBarFactory
23
24 1
    ) {}
25
26 20
    #[Override]
27
    public function createSystemData(
28
        SpacecraftSystemTypeEnum $systemType,
29
        SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory
30
    ): AbstractSystemData {
31
        switch ($systemType) {
32 20
            case SpacecraftSystemTypeEnum::HULL:
33 9
                return  new HullSystemData(
34 9
                    $this->shipSystemRepository,
35 9
                    $this->statusBarFactory
36 9
                );
37 16
            case SpacecraftSystemTypeEnum::SHIELDS:
38 4
                return  new ShieldSystemData(
39 4
                    $this->shipSystemRepository,
40 4
                    $this->statusBarFactory
41 4
                );
42 16
            case SpacecraftSystemTypeEnum::EPS:
43 12
                return  new EpsSystemData(
44 12
                    $this->shipSystemRepository,
45 12
                    $this->statusBarFactory
46 12
                );
47 11
            case SpacecraftSystemTypeEnum::COMPUTER:
48 5
                return  new ComputerSystemData(
49 5
                    $this->shipSystemRepository,
50 5
                    $this->statusBarFactory
51 5
                );
52 10
            case SpacecraftSystemTypeEnum::TRACKER:
53
                return  new TrackerSystemData(
54
                    $this->shipRepository,
55
                    $spacecraftWrapperFactory,
56
                    $this->shipSystemRepository,
57
                    $this->statusBarFactory
58
                );
59 10
            case SpacecraftSystemTypeEnum::THOLIAN_WEB:
60 1
                return  new WebEmitterSystemData(
61 1
                    $this->shipSystemRepository,
62 1
                    $this->tholianWebRepository,
63 1
                    $this->statusBarFactory
64 1
                );
65 9
            case SpacecraftSystemTypeEnum::WARPDRIVE:
66 5
                return  new WarpDriveSystemData(
67 5
                    $this->shipSystemRepository,
68 5
                    $this->statusBarFactory
69 5
                );
70 7
            case SpacecraftSystemTypeEnum::WARPCORE:
71 5
                return  new WarpCoreSystemData(
72 5
                    $this->shipSystemRepository,
73 5
                    $this->statusBarFactory
74 5
                );
75 4
            case SpacecraftSystemTypeEnum::SINGULARITY_REACTOR:
76
                return  new SingularityCoreSystemData(
77
                    $this->shipSystemRepository,
78
                    $this->statusBarFactory
79
                );
80 4
            case SpacecraftSystemTypeEnum::FUSION_REACTOR:
81
                return  new FusionCoreSystemData(
82
                    $this->shipSystemRepository,
83
                    $this->statusBarFactory
84
                );
85 4
            case SpacecraftSystemTypeEnum::ASTRO_LABORATORY:
86
                return  new AstroLaboratorySystemData(
87
                    $this->shipSystemRepository,
88
                    $this->statusBarFactory
89
                );
90 4
            case SpacecraftSystemTypeEnum::PHASER:
91 1
                return  new EnergyWeaponSystemData(
92 1
                    $this->shipSystemRepository,
93 1
                    $this->statusBarFactory
94 1
                );
95 4
            case SpacecraftSystemTypeEnum::TORPEDO:
96
                return  new ProjectileLauncherSystemData(
97
                    $this->shipSystemRepository,
98
                    $this->statusBarFactory
99
                );
100 4
            case SpacecraftSystemTypeEnum::BUSSARD_COLLECTOR:
101 1
                return  new BussardCollectorSystemData(
102 1
                    $this->shipSystemRepository,
103 1
                    $this->statusBarFactory
104 1
                );
105 3
            case SpacecraftSystemTypeEnum::AGGREGATION_SYSTEM:
106 1
                return  new AggregationSystemSystemData(
107 1
                    $this->shipSystemRepository,
108 1
                    $this->statusBarFactory
109 1
                );
110 2
            case SpacecraftSystemTypeEnum::LSS:
111 2
                return  new LssSystemData(
112 2
                    $this->shipSystemRepository,
113 2
                    $this->statusBarFactory
114 2
                );
115
        }
116
117
        throw new InvalidSystemException(sprintf('no system data present for systemType: %d', $systemType->value));
118
    }
119
}
120