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

ShipSystemDataFactory::createSystemData()   C

Complexity

Conditions 14
Paths 14

Size

Total Lines 77
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 56.3359

Importance

Changes 0
Metric Value
cc 14
eloc 58
nc 14
nop 2
dl 0
loc 77
ccs 28
cts 70
cp 0.4
crap 56.3359
rs 6.2666
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 13
    #[Override]
27
    public function createSystemData(
28
        SpacecraftSystemTypeEnum $systemType,
29
        SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory
30
    ): AbstractSystemData {
31
        switch ($systemType) {
32 13
            case SpacecraftSystemTypeEnum::SYSTEM_HULL:
33 8
                return  new HullSystemData(
34 8
                    $this->shipSystemRepository,
35 8
                    $this->statusBarFactory
36 8
                );
37 9
            case SpacecraftSystemTypeEnum::SYSTEM_SHIELDS:
38 4
                return  new ShieldSystemData(
39 4
                    $this->shipSystemRepository,
40 4
                    $this->statusBarFactory
41 4
                );
42 9
            case SpacecraftSystemTypeEnum::SYSTEM_EPS:
43 9
                return  new EpsSystemData(
44 9
                    $this->shipSystemRepository,
45 9
                    $this->statusBarFactory
46 9
                );
47 5
            case SpacecraftSystemTypeEnum::SYSTEM_TRACKER:
48
                return  new TrackerSystemData(
49
                    $this->shipRepository,
50
                    $spacecraftWrapperFactory,
51
                    $this->shipSystemRepository,
52
                    $this->statusBarFactory
53
                );
54 5
            case SpacecraftSystemTypeEnum::SYSTEM_THOLIAN_WEB:
55
                return  new WebEmitterSystemData(
56
                    $this->shipSystemRepository,
57
                    $this->tholianWebRepository,
58
                    $this->statusBarFactory
59
                );
60 5
            case SpacecraftSystemTypeEnum::SYSTEM_WARPDRIVE:
61 3
                return  new WarpDriveSystemData(
62 3
                    $this->shipSystemRepository,
63 3
                    $this->statusBarFactory
64 3
                );
65 5
            case SpacecraftSystemTypeEnum::SYSTEM_WARPCORE:
66 5
                return  new WarpCoreSystemData(
67 5
                    $this->shipSystemRepository,
68 5
                    $this->statusBarFactory
69 5
                );
70
            case SpacecraftSystemTypeEnum::SYSTEM_SINGULARITY_REACTOR:
71
                return  new SingularityCoreSystemData(
72
                    $this->shipSystemRepository,
73
                    $this->statusBarFactory
74
                );
75
            case SpacecraftSystemTypeEnum::SYSTEM_FUSION_REACTOR:
76
                return  new FusionCoreSystemData(
77
                    $this->shipSystemRepository,
78
                    $this->statusBarFactory
79
                );
80
            case SpacecraftSystemTypeEnum::SYSTEM_ASTRO_LABORATORY:
81
                return  new AstroLaboratorySystemData(
82
                    $this->shipSystemRepository,
83
                    $this->statusBarFactory
84
                );
85
            case SpacecraftSystemTypeEnum::SYSTEM_TORPEDO:
86
                return  new ProjectileLauncherSystemData(
87
                    $this->shipSystemRepository,
88
                    $this->statusBarFactory
89
                );
90
            case SpacecraftSystemTypeEnum::SYSTEM_BUSSARD_COLLECTOR:
91
                return  new BussardCollectorSystemData(
92
                    $this->shipSystemRepository,
93
                    $this->statusBarFactory
94
                );
95
            case SpacecraftSystemTypeEnum::SYSTEM_AGGREGATION_SYSTEM:
96
                return  new AggregationSystemSystemData(
97
                    $this->shipSystemRepository,
98
                    $this->statusBarFactory
99
                );
100
        }
101
102
        throw new InvalidSystemException(sprintf('no system data present for systemType: %d', $systemType->value));
103
    }
104
}
105