Passed
Push — dev ( 216c8f...156d5c )
by Janko
15:03
created

ModuleRumpWrapperWarpDrive   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 26.67%

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 56
ccs 8
cts 30
cp 0.2667
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 16 2
A getValue() 0 12 2
A apply() 0 15 3
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\Player\Settings\UserSettingsProviderInterface;
10
use Stu\Component\Spacecraft\SpacecraftModuleTypeEnum;
11
use Stu\Config\Init;
12
use Stu\Module\Spacecraft\Lib\ModuleValueCalculator;
13
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
14
use Stu\Orm\Entity\ModuleInterface;
15
16
final class ModuleRumpWrapperWarpDrive 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->getBaseWarpDrive()
30 3
        );
31
    }
32
33
    #[Override]
34
    public function getModuleType(): SpacecraftModuleTypeEnum
35
    {
36
        return SpacecraftModuleTypeEnum::WARPDRIVE;
37
    }
38
39
    #[Override]
40
    public function initialize(SpacecraftWrapperInterface $wrapper): ModuleRumpWrapperInterface
41
    {
42
        $systemData = $wrapper->getWarpDriveSystemData();
43
        if ($systemData === null) {
44
            throw new RuntimeException('this should not happen');
45
        }
46
47
        $userSettingsProvider = Init::getContainer()->get(UserSettingsProviderInterface::class);
48
        $isAutoCarryOver = $userSettingsProvider->getWarpsplitAutoCarryoverDefault($wrapper->get()->getUser());
49
50
        $systemData
51
            ->setAutoCarryOver($isAutoCarryOver)
52
            ->update();
53
54
        return $this;
55
    }
56
57
    #[Override]
58
    public function apply(SpacecraftWrapperInterface $wrapper): void
59
    {
60
        $systemData = $wrapper->getWarpDriveSystemData();
61
        if ($systemData === null) {
62
            throw new RuntimeException('this should not happen');
63
        }
64
65
        if ($systemData->getWarpDrive() > $this->getValue()) {
66
            $systemData->setWarpDrive($this->getValue());
67
        }
68
69
        $systemData
70
            ->setMaxWarpDrive($this->getValue())
71
            ->update();
72
    }
73
}
74