Passed
Push — master ( cc891d...b53f20 )
by Nico
11:42
created

ShipSystemDataFactory::createSystemData()   C

Complexity

Conditions 15
Paths 15

Size

Total Lines 82
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 52
CRAP Score 21.4911

Importance

Changes 0
Metric Value
cc 15
eloc 62
c 0
b 0
f 0
nc 15
nop 2
dl 0
loc 82
ccs 52
cts 75
cp 0.6933
crap 21.4911
rs 5.9166

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 16
    #[Override]
27
    public function createSystemData(
28
        SpacecraftSystemTypeEnum $systemType,
29
        SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory
30
    ): AbstractSystemData {
31
        switch ($systemType) {
32 16
            case SpacecraftSystemTypeEnum::HULL:
33 8
                return  new HullSystemData(
34 8
                    $this->shipSystemRepository,
35 8
                    $this->statusBarFactory
36 8
                );
37 12
            case SpacecraftSystemTypeEnum::SHIELDS:
38 4
                return  new ShieldSystemData(
39 4
                    $this->shipSystemRepository,
40 4
                    $this->statusBarFactory
41 4
                );
42 12
            case SpacecraftSystemTypeEnum::EPS:
43 9
                return  new EpsSystemData(
44 9
                    $this->shipSystemRepository,
45 9
                    $this->statusBarFactory
46 9
                );
47 8
            case SpacecraftSystemTypeEnum::TRACKER:
48
                return  new TrackerSystemData(
49
                    $this->shipRepository,
50
                    $spacecraftWrapperFactory,
51
                    $this->shipSystemRepository,
52
                    $this->statusBarFactory
53
                );
54 8
            case SpacecraftSystemTypeEnum::THOLIAN_WEB:
55 1
                return  new WebEmitterSystemData(
56 1
                    $this->shipSystemRepository,
57 1
                    $this->tholianWebRepository,
58 1
                    $this->statusBarFactory
59 1
                );
60 7
            case SpacecraftSystemTypeEnum::WARPDRIVE:
61 3
                return  new WarpDriveSystemData(
62 3
                    $this->shipSystemRepository,
63 3
                    $this->statusBarFactory
64 3
                );
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::TORPEDO:
86
                return  new ProjectileLauncherSystemData(
87
                    $this->shipSystemRepository,
88
                    $this->statusBarFactory
89
                );
90 4
            case SpacecraftSystemTypeEnum::BUSSARD_COLLECTOR:
91 1
                return  new BussardCollectorSystemData(
92 1
                    $this->shipSystemRepository,
93 1
                    $this->statusBarFactory
94 1
                );
95 3
            case SpacecraftSystemTypeEnum::AGGREGATION_SYSTEM:
96 1
                return  new AggregationSystemSystemData(
97 1
                    $this->shipSystemRepository,
98 1
                    $this->statusBarFactory
99 1
                );
100 2
            case SpacecraftSystemTypeEnum::LSS:
101 2
                return  new LssSystemData(
102 2
                    $this->shipSystemRepository,
103 2
                    $this->statusBarFactory
104 2
                );
105
        }
106
107
        throw new InvalidSystemException(sprintf('no system data present for systemType: %d', $systemType->value));
108
    }
109
}
110