Passed
Push — dev ( 98511f...00baf5 )
by Janko
15:17
created

ShipSystemDataFactory::createSystemData()   C

Complexity

Conditions 16
Paths 16

Size

Total Lines 87
Code Lines 66

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 57
CRAP Score 22.0834

Importance

Changes 0
Metric Value
cc 16
eloc 66
c 0
b 0
f 0
nc 16
nop 2
dl 0
loc 87
ccs 57
cts 80
cp 0.7125
crap 22.0834
rs 5.5666

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 19
    #[Override]
27
    public function createSystemData(
28
        SpacecraftSystemTypeEnum $systemType,
29
        SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory
30
    ): AbstractSystemData {
31
        switch ($systemType) {
32 19
            case SpacecraftSystemTypeEnum::HULL:
33 9
                return  new HullSystemData(
34 9
                    $this->shipSystemRepository,
35 9
                    $this->statusBarFactory
36 9
                );
37 15
            case SpacecraftSystemTypeEnum::SHIELDS:
38 4
                return  new ShieldSystemData(
39 4
                    $this->shipSystemRepository,
40 4
                    $this->statusBarFactory
41 4
                );
42 15
            case SpacecraftSystemTypeEnum::EPS:
43 12
                return  new EpsSystemData(
44 12
                    $this->shipSystemRepository,
45 12
                    $this->statusBarFactory
46 12
                );
47 10
            case SpacecraftSystemTypeEnum::TRACKER:
48
                return  new TrackerSystemData(
49
                    $this->shipRepository,
50
                    $spacecraftWrapperFactory,
51
                    $this->shipSystemRepository,
52
                    $this->statusBarFactory
53
                );
54 10
            case SpacecraftSystemTypeEnum::THOLIAN_WEB:
55 1
                return  new WebEmitterSystemData(
56 1
                    $this->shipSystemRepository,
57 1
                    $this->tholianWebRepository,
58 1
                    $this->statusBarFactory
59 1
                );
60 9
            case SpacecraftSystemTypeEnum::WARPDRIVE:
61 5
                return  new WarpDriveSystemData(
62 5
                    $this->shipSystemRepository,
63 5
                    $this->statusBarFactory
64 5
                );
65 7
            case SpacecraftSystemTypeEnum::WARPCORE:
66 5
                return  new WarpCoreSystemData(
67 5
                    $this->shipSystemRepository,
68 5
                    $this->statusBarFactory
69 5
                );
70 4
            case SpacecraftSystemTypeEnum::SINGULARITY_REACTOR:
71
                return  new SingularityCoreSystemData(
72
                    $this->shipSystemRepository,
73
                    $this->statusBarFactory
74
                );
75 4
            case SpacecraftSystemTypeEnum::FUSION_REACTOR:
76
                return  new FusionCoreSystemData(
77
                    $this->shipSystemRepository,
78
                    $this->statusBarFactory
79
                );
80 4
            case SpacecraftSystemTypeEnum::ASTRO_LABORATORY:
81
                return  new AstroLaboratorySystemData(
82
                    $this->shipSystemRepository,
83
                    $this->statusBarFactory
84
                );
85 4
            case SpacecraftSystemTypeEnum::PHASER:
86 1
                return  new EnergyWeaponSystemData(
87 1
                    $this->shipSystemRepository,
88 1
                    $this->statusBarFactory
89 1
                );
90 4
            case SpacecraftSystemTypeEnum::TORPEDO:
91
                return  new ProjectileLauncherSystemData(
92
                    $this->shipSystemRepository,
93
                    $this->statusBarFactory
94
                );
95 4
            case SpacecraftSystemTypeEnum::BUSSARD_COLLECTOR:
96 1
                return  new BussardCollectorSystemData(
97 1
                    $this->shipSystemRepository,
98 1
                    $this->statusBarFactory
99 1
                );
100 3
            case SpacecraftSystemTypeEnum::AGGREGATION_SYSTEM:
101 1
                return  new AggregationSystemSystemData(
102 1
                    $this->shipSystemRepository,
103 1
                    $this->statusBarFactory
104 1
                );
105 2
            case SpacecraftSystemTypeEnum::LSS:
106 2
                return  new LssSystemData(
107 2
                    $this->shipSystemRepository,
108 2
                    $this->statusBarFactory
109 2
                );
110
        }
111
112
        throw new InvalidSystemException(sprintf('no system data present for systemType: %d', $systemType->value));
113
    }
114
}
115