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

ModuleRumpWrapperBase::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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