Passed
Push — master ( 996fbb...d0c183 )
by Nico
44:00 queued 29:21
created

SpacecraftWrapperSystemDataTrait   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 93.88%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 42
c 1
b 0
f 0
dl 0
loc 91
ccs 46
cts 49
cp 0.9388
rs 10
wmc 12

9 Methods

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