Passed
Push — master ( a3f62b...37016c )
by Nico
54:32 queued 29:36
created

ModuleRumpWrapperEps   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 42
ccs 0
cts 21
cp 0
rs 10
c 2
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 12 2
A apply() 0 9 2
A getSecondValue() 0 8 2
A getModuleType() 0 4 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\Ship\ShipModuleTypeEnum;
10
use Stu\Module\Ship\Lib\ModuleValueCalculator;
11
use Stu\Module\Ship\Lib\ShipWrapperInterface;
12
use Stu\Orm\Entity\ModuleInterface;
13
14
final class ModuleRumpWrapperEps extends ModuleRumpWrapperBase implements ModuleRumpWrapperInterface
15
{
16
    #[Override]
17
    public function getValue(?ModuleInterface $module = null): int
18
    {
19
        $module ??= current($this->getModule());
20
        if ($module === false) {
21
            return 0;
22
        }
23
24
        return (new ModuleValueCalculator())->calculateModuleValue(
25
            $this->rump,
26
            $module,
27
            $this->rump->getBaseEps()
28
        );
29
    }
30
31
    #[Override]
32
    public function getSecondValue(?ModuleInterface $module = null): ?int
33
    {
34
        $module ??= current($this->getModule());
35
        if ($module === false) {
36
            return null;
37
        }
38
        return (int) round($this->getValue($module) / 3);
39
    }
40
41
    #[Override]
42
    public function getModuleType(): ShipModuleTypeEnum
43
    {
44
        return ShipModuleTypeEnum::EPS;
45
    }
46
47
    #[Override]
48
    public function apply(ShipWrapperInterface $wrapper): void
49
    {
50
        $epsSystem = $wrapper->getEpsSystemData();
51
        if ($epsSystem === null) {
52
            throw new RuntimeException('this should not happen');
53
        }
54
55
        $epsSystem->setMaxEps($this->getValue())->update();
56
    }
57
}
58