Passed
Pull Request — master (#1884)
by Janko
50:38 queued 25:12
created

ShipSystemDataFactory   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 3.23%

Importance

Changes 0
Metric Value
eloc 51
dl 0
loc 76
ccs 2
cts 62
cp 0.0323
rs 10
c 0
b 0
f 0
wmc 13

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
C createSystemData() 0 67 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Ship\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\Ship\System\Exception\InvalidSystemException;
9
use Stu\Component\Ship\System\ShipSystemTypeEnum;
10
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface;
11
use Stu\Module\Template\StatusBarFactoryInterface;
12
use Stu\Orm\Repository\ShipRepositoryInterface;
13
use Stu\Orm\Repository\ShipSystemRepositoryInterface;
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 ShipSystemRepositoryInterface $shipSystemRepository,
21
        private TholianWebRepositoryInterface $tholianWebRepository,
22
        private StatusBarFactoryInterface $statusBarFactory
23 1
    ) {}
24
25
    #[Override]
26
    public function createSystemData(
27
        ShipSystemTypeEnum $systemType,
28
        ShipWrapperFactoryInterface $shipWrapperFactory
29
    ): AbstractSystemData {
30
        switch ($systemType) {
31
            case ShipSystemTypeEnum::SYSTEM_HULL:
32
                return  new HullSystemData(
33
                    $this->shipSystemRepository,
34
                    $this->statusBarFactory
35
                );
36
            case ShipSystemTypeEnum::SYSTEM_SHIELDS:
37
                return  new ShieldSystemData(
38
                    $this->shipSystemRepository,
39
                    $this->statusBarFactory
40
                );
41
            case ShipSystemTypeEnum::SYSTEM_EPS:
42
                return  new EpsSystemData(
43
                    $this->shipSystemRepository,
44
                    $this->statusBarFactory
45
                );
46
            case ShipSystemTypeEnum::SYSTEM_TRACKER:
47
                return  new TrackerSystemData(
48
                    $this->shipRepository,
49
                    $shipWrapperFactory,
50
                    $this->shipSystemRepository,
51
                    $this->statusBarFactory
52
                );
53
            case ShipSystemTypeEnum::SYSTEM_THOLIAN_WEB:
54
                return  new WebEmitterSystemData(
55
                    $this->shipSystemRepository,
56
                    $this->tholianWebRepository,
57
                    $this->statusBarFactory
58
                );
59
            case ShipSystemTypeEnum::SYSTEM_WARPDRIVE:
60
                return  new WarpDriveSystemData(
61
                    $this->shipSystemRepository,
62
                    $this->statusBarFactory
63
                );
64
            case ShipSystemTypeEnum::SYSTEM_WARPCORE:
65
                return  new WarpCoreSystemData(
66
                    $this->shipSystemRepository,
67
                    $this->statusBarFactory
68
                );
69
            case ShipSystemTypeEnum::SYSTEM_SINGULARITY_REACTOR:
70
                return  new SingularityCoreSystemData(
71
                    $this->shipSystemRepository,
72
                    $this->statusBarFactory
73
                );
74
            case ShipSystemTypeEnum::SYSTEM_FUSION_REACTOR:
75
                return  new FusionCoreSystemData(
76
                    $this->shipSystemRepository,
77
                    $this->statusBarFactory
78
                );
79
            case ShipSystemTypeEnum::SYSTEM_ASTRO_LABORATORY:
80
                return  new AstroLaboratorySystemData(
81
                    $this->shipSystemRepository,
82
                    $this->statusBarFactory
83
                );
84
            case ShipSystemTypeEnum::SYSTEM_TORPEDO:
85
                return  new ProjectileLauncherSystemData(
86
                    $this->shipSystemRepository,
87
                    $this->statusBarFactory
88
                );
89
        }
90
91
        throw new InvalidSystemException(sprintf('no system data present for systemType: %d', $systemType->value));
92
    }
93
}
94