Passed
Branch master (89bdb5)
by Janko
11:58
created

ReactorWrapperFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 61.9%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 31
ccs 13
cts 21
cp 0.619
rs 10
c 1
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A createReactorWrapper() 0 29 5
1
<?php
2
3
namespace Stu\Module\Spacecraft\Lib\Reactor;
4
5
use Stu\Component\Spacecraft\System\Data\FusionCoreSystemData;
6
use Stu\Component\Spacecraft\System\Data\SingularityCoreSystemData;
7
use Stu\Component\Spacecraft\System\Data\WarpCoreSystemData;
8
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
9
use Stu\Module\Spacecraft\Lib\ReactorWrapper;
10
use Stu\Module\Spacecraft\Lib\ReactorWrapperInterface;
11
use Stu\Module\Spacecraft\Lib\SpacecraftWrapper;
12
13
class ReactorWrapperFactory implements ReactorWrapperFactoryInterface
14
{
15 9
    public function createReactorWrapper(SpacecraftWrapper $wrapper): ?ReactorWrapperInterface
16
    {
17 9
        $reactorSystemData = null;
18 9
        $spacecraft = $wrapper->get();
19
20 9
        if ($spacecraft->hasSpacecraftSystem(SpacecraftSystemTypeEnum::WARPCORE)) {
21 5
            $reactorSystemData = $wrapper->getSpecificShipSystem(
22 5
                SpacecraftSystemTypeEnum::WARPCORE,
23 5
                WarpCoreSystemData::class
24 5
            );
25
        }
26 9
        if ($spacecraft->hasSpacecraftSystem(SpacecraftSystemTypeEnum::SINGULARITY_REACTOR)) {
27
            $reactorSystemData = $wrapper->getSpecificShipSystem(
28
                SpacecraftSystemTypeEnum::SINGULARITY_REACTOR,
29
                SingularityCoreSystemData::class
30
            );
31
        }
32 9
        if ($spacecraft->hasSpacecraftSystem(SpacecraftSystemTypeEnum::FUSION_REACTOR)) {
33
            $reactorSystemData = $wrapper->getSpecificShipSystem(
34
                SpacecraftSystemTypeEnum::FUSION_REACTOR,
35
                FusionCoreSystemData::class
36
            );
37
        }
38
39 9
        if ($reactorSystemData === null) {
40 6
            return null;
41
        }
42
43 5
        return new ReactorWrapper($wrapper, $reactorSystemData);
44
    }
45
}
46