Passed
Push — master ( eed220...e3ff64 )
by Janko
21:01 queued 11:01
created

SpacecraftWrapperSystemDataTrait   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Test Coverage

Coverage 87.04%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 46
c 1
b 0
f 0
dl 0
loc 98
ccs 47
cts 54
cp 0.8704
rs 10
wmc 13

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getProjectileLauncherSystemData() 0 6 1
A getEnergyWeaponSystemData() 0 6 1
A getHullSystemData() 0 13 2
A getComputerSystemDataMandatory() 0 12 2
A getWarpDriveSystemData() 0 6 1
A getEpsSystemData() 0 6 1
A getLssSystemData() 0 6 1
A getShieldSystemData() 0 6 1
A getThis() 0 7 2
A getSubspaceSystemData() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Spacecraft\Lib;
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 RuntimeException;
9
use Stu\Component\Spacecraft\System\Data\ComputerSystemData;
10
use Stu\Component\Spacecraft\System\Data\EnergyWeaponSystemData;
11
use Stu\Component\Spacecraft\System\Data\EpsSystemData;
12
use Stu\Component\Spacecraft\System\Data\HullSystemData;
13
use Stu\Component\Spacecraft\System\Data\LssSystemData;
14
use Stu\Component\Spacecraft\System\Data\ProjectileLauncherSystemData;
15
use Stu\Component\Spacecraft\System\Data\ShieldSystemData;
16
use Stu\Component\Spacecraft\System\Data\SubspaceSystemData;
17
use Stu\Component\Spacecraft\System\Data\WarpDriveSystemData;
18
use Stu\Component\Spacecraft\System\Exception\SystemNotFoundException;
19
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
20
21
trait SpacecraftWrapperSystemDataTrait
22
{
23 24
    private function getThis(): SpacecraftWrapper
24
    {
25 24
        if (!$this instanceof SpacecraftWrapper) {
26
            throw new RuntimeException('trait can only be used on spacecraft wrapper');
27
        }
28
29 24
        return $this;
30
    }
31
32 10
    #[Override]
33
    public function getHullSystemData(): HullSystemData
34
    {
35 10
        $hullSystemData = $this->getThis()->getSpecificShipSystem(
36 10
            SpacecraftSystemTypeEnum::HULL,
37 10
            HullSystemData::class
38 10
        );
39
40 10
        if ($hullSystemData === null) {
41
            throw new SystemNotFoundException('no hull installed?');
42
        }
43
44 10
        return $hullSystemData;
45
    }
46
47 9
    #[Override]
48
    public function getShieldSystemData(): ?ShieldSystemData
49
    {
50 9
        return $this->getThis()->getSpecificShipSystem(
51 9
            SpacecraftSystemTypeEnum::SHIELDS,
52 9
            ShieldSystemData::class
53 9
        );
54
    }
55
56 20
    #[Override]
57
    public function getEpsSystemData(): ?EpsSystemData
58
    {
59 20
        return $this->getThis()->getSpecificShipSystem(
60 20
            SpacecraftSystemTypeEnum::EPS,
61 20
            EpsSystemData::class
62 20
        );
63
    }
64
65 6
    #[Override]
66
    public function getComputerSystemDataMandatory(): ComputerSystemData
67
    {
68 6
        $computer = $this->getThis()->getSpecificShipSystem(
69 6
            SpacecraftSystemTypeEnum::COMPUTER,
70 6
            ComputerSystemData::class
71 6
        );
72 6
        if ($computer === null) {
73
            throw new SystemNotFoundException('no computer installed?');
74
        }
75
76 6
        return $computer;
77
    }
78
79 4
    #[Override]
80
    public function getLssSystemData(): ?LssSystemData
81
    {
82 4
        return $this->getThis()->getSpecificShipSystem(
83 4
            SpacecraftSystemTypeEnum::LSS,
84 4
            LssSystemData::class
85 4
        );
86
    }
87
88 2
    #[Override]
89
    public function getEnergyWeaponSystemData(): ?EnergyWeaponSystemData
90
    {
91 2
        return $this->getThis()->getSpecificShipSystem(
92 2
            SpacecraftSystemTypeEnum::PHASER,
93 2
            EnergyWeaponSystemData::class
94 2
        );
95
    }
96
97 10
    #[Override]
98
    public function getWarpDriveSystemData(): ?WarpDriveSystemData
99
    {
100 10
        return $this->getThis()->getSpecificShipSystem(
101 10
            SpacecraftSystemTypeEnum::WARPDRIVE,
102 10
            WarpDriveSystemData::class
103 10
        );
104
    }
105 2
    #[Override]
106
    public function getProjectileLauncherSystemData(): ?ProjectileLauncherSystemData
107
    {
108 2
        return $this->getThis()->getSpecificShipSystem(
109 2
            SpacecraftSystemTypeEnum::TORPEDO,
110 2
            ProjectileLauncherSystemData::class
111 2
        );
112
    }
113
    #[Override]
114
    public function getSubspaceSystemData(): ?SubspaceSystemData
115
    {
116
        return $this->getThis()->getSpecificShipSystem(
117
            SpacecraftSystemTypeEnum::SUBSPACE_SCANNER,
118
            SubspaceSystemData::class
119
        );
120
    }
121
}
122