Passed
Push — dev ( 2ba144...6e3434 )
by Janko
17:42
created

ModuleRumpWrapperBase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 15.38%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 40
rs 10
c 0
b 0
f 0
ccs 2
cts 13
cp 0.1538
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A getSecondValue() 0 4 1
A getModule() 0 11 3
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\ModuleRumpWrapper;
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\SpacecraftModuleTypeEnum;
10
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
11
use Stu\Orm\Entity\ModuleInterface;
12
use Stu\Orm\Entity\SpacecraftBuildplanInterface;
13
use Stu\Orm\Entity\SpacecraftRumpBaseValuesInterface;
14
use Stu\Orm\Entity\SpacecraftRumpInterface;
15
16
abstract class ModuleRumpWrapperBase implements ModuleRumpWrapperInterface
17
{
18
    /** @var null|array<int, ModuleInterface> */
19
    private ?array $modules = null;
20
21
    protected SpacecraftRumpBaseValuesInterface $rumpBaseValues;
22
23 3
    public function __construct(
24
        protected SpacecraftRumpInterface $rump,
25
        private ?SpacecraftBuildplanInterface $buildplan
26
    ) {
27 3
        $this->rumpBaseValues = $rump->getBaseValues();
28
    }
29
30
    abstract public function getModuleType(): SpacecraftModuleTypeEnum;
31
32
    #[Override]
33
    public function getModule(): iterable
34
    {
35
        if ($this->modules === null) {
36
            $buildplan = $this->buildplan;
37
            $this->modules = $buildplan === null
38
                ? []
39
                : $buildplan->getModulesByType($this->getModuleType())->toArray();
40
        }
41
42
        return $this->modules;
43
    }
44
45
    #[Override]
46
    public function getSecondValue(?ModuleInterface $module = null): int
47
    {
48
        throw new RuntimeException(sprintf('not implemented for moduleType: %s', $this->getModuleType()->name));
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Stu\Component\Spacecraft\SpacecraftModuleTypeEnum.
Loading history...
49
    }
50
51
    #[Override]
52
    public function initialize(SpacecraftWrapperInterface $wrapper): ModuleRumpWrapperInterface
53
    {
54
        //override if neccessary
55
        return $this;
56
    }
57
}
58