Passed
Push — dev ( 3a023f...594b62 )
by Janko
09:47
created

ModuleRumpWrapperReactor::apply()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 4
eloc 7
nc 3
nop 1
dl 0
loc 13
ccs 0
cts 7
cp 0
crap 20
rs 10
c 1
b 1
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\ModuleValueCalculator;
11
use Stu\Orm\Entity\ModuleInterface;
12
use Stu\Module\Spacecraft\Lib\ReactorWrapperInterface;
13
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
14
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
15
16
final class ModuleRumpWrapperReactor extends ModuleRumpWrapperBase implements ModuleRumpWrapperInterface
17
{
18 3
    #[Override]
19
    public function getValue(?ModuleInterface $module = null): int
20
    {
21 3
        $module ??= current($this->getModule());
22 3
        if ($module === false) {
23
            return 0;
24
        }
25
26 3
        return (new ModuleValueCalculator())->calculateModuleValue(
27 3
            $this->rump,
28 3
            $module,
29 3
            $this->rump->getBaseReactor()
30 3
        );
31
    }
32
33 3
    #[Override]
34
    public function getSecondValue(?ModuleInterface $module = null): int
35
    {
36 3
        $module ??= current($this->getModule());
37 3
        if ($module === false) {
38
            return 0;
39
        }
40 3
        if ($module->getSystemType() == SpacecraftSystemTypeEnum::SINGULARITY_REACTOR) {
41 3
            return $this->getValue($module) * ReactorWrapperInterface::SINGULARITY_CAPACITY_MULTIPLIER;
42
        }
43 3
        if ($module->getSystemType() == SpacecraftSystemTypeEnum::FUSION_REACTOR) {
44
            return $this->getValue($module) * ReactorWrapperInterface::FUSIONCORE_CAPACITY_MULTIPLIER;
45
        } else {
46 3
            return $this->getValue($module) * ReactorWrapperInterface::WARPCORE_CAPACITY_MULTIPLIER;
47
        }
48
    }
49
50
    #[Override]
51
    public function getModuleType(): SpacecraftModuleTypeEnum
52
    {
53
        return SpacecraftModuleTypeEnum::REACTOR;
54
    }
55
56
    #[Override]
57
    public function apply(SpacecraftWrapperInterface $wrapper): void
58
    {
59
        $reactorWrapper = $wrapper->getReactorWrapper();
60
        if ($reactorWrapper === null) {
61
            throw new RuntimeException('this should not happen');
62
        }
63
64
        if ($reactorWrapper->getLoad() > $this->getSecondValue() && $this->getSecondValue()) {
65
            $reactorWrapper->setLoad($this->getSecondValue());
66
        }
67
68
        $reactorWrapper->setOutput($this->getValue());
69
    }
70
}