Passed
Push — dev ( 0dbbcc...f29cfd )
by Janko
10:15
created

ModuleRumpWrapperBase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 7.14%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 37
ccs 1
cts 14
cp 0.0714
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A getSecondValue() 0 4 1
A getModule() 0 15 3
A __construct() 0 1 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\SpacecraftRumpInterface;
14
15
abstract class ModuleRumpWrapperBase implements ModuleRumpWrapperInterface
16
{
17
    /** @var null|array<int, ModuleInterface> */
18
    private ?array $modules = null;
19
20 3
    public function __construct(protected SpacecraftRumpInterface $rump, private ?SpacecraftBuildplanInterface $buildplan) {}
21
22
    abstract public function getModuleType(): SpacecraftModuleTypeEnum;
23
24
    #[Override]
25
    public function getModule(): iterable
26
    {
27
        if ($this->modules === null) {
28
            $buildplan = $this->buildplan;
29
            if ($buildplan === null) {
30
                $this->modules = [];
31
            } else {
32
                $this->modules = $buildplan
33
                    ->getModulesByType($this->getModuleType())
34
                    ->toArray();
35
            }
36
        }
37
38
        return $this->modules;
39
    }
40
41
    #[Override]
42
    public function getSecondValue(?ModuleInterface $module = null): int
43
    {
44
        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...
45
    }
46
47
    #[Override]
48
    public function initialize(SpacecraftWrapperInterface $wrapper): ModuleRumpWrapperInterface
49
    {
50
        //override if neccessary
51
        return $this;
52
    }
53
}
54