Passed
Push — dev ( 2ba144...6e3434 )
by Janko
17:42
created

ModuleValueCalculator   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 58.33%

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 68
rs 10
c 0
b 0
f 0
ccs 21
cts 36
cp 0.5833
wmc 16

3 Methods

Rating   Name   Duplication   Size   Complexity  
B calculateModuleValue() 0 31 8
A calculateDamageImpact() 0 15 4
A calculateEvadeChance() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Spacecraft\Lib;
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 Stu\Component\Spacecraft\SpacecraftModuleTypeEnum;
9
use Stu\Orm\Entity\ModuleInterface;
10
use Stu\Orm\Entity\SpacecraftRumpInterface;
11
12
final class ModuleValueCalculator implements ModuleValueCalculatorInterface
13
{
14 3
    #[Override]
15
    public function calculateModuleValue(
16
        SpacecraftRumpInterface $rump,
17
        ModuleInterface $module,
18
        int $value
19
    ): int {
20
21 3
        $moduleLevel = $rump->getBaseValues()->getModuleLevel();
22
23 3
        if ($module->getType() === SpacecraftModuleTypeEnum::SENSOR) {
24 3
            if ($moduleLevel > $module->getLevel()) {
25 3
                return (int) round($value -  $module->getDowngradeFactor());
26
            }
27
            if ($moduleLevel < $module->getLevel()) {
28
                return (int) round($value +  $module->getUpgradeFactor());
29
            }
30
            if ($moduleLevel === $module->getLevel()) {
31
                return (int) round($value +  $module->getDefaultFactor());
32
            }
33
        } else {
34 3
            if ($moduleLevel > $module->getLevel()) {
35 3
                return (int) round($value - $value / 100 * $module->getDowngradeFactor());
36
            }
37 3
            if ($moduleLevel < $module->getLevel()) {
38 3
                return (int) round($value + $value / 100 * $module->getUpgradeFactor());
39
            }
40 3
            if ($moduleLevel === $module->getLevel()) {
41 3
                return (int) round($value + $value / 100 * $module->getDefaultFactor());
42
            }
43
        }
44
        return $value;
45
    }
46
47
    #[Override]
48
    public function calculateDamageImpact(SpacecraftRumpInterface $rump, ModuleInterface $module): string
49
    {
50
        $moduleLevel = $rump->getBaseValues()->getModuleLevel();
51
52
        if ($moduleLevel > $module->getLevel()) {
53
            return '-' . $module->getDowngradeFactor() . '%';
54
        }
55
        if ($moduleLevel < $module->getLevel()) {
56
            return '+' . $module->getUpgradeFactor() . '%';
57
        }
58
        if ($moduleLevel === $module->getLevel()) {
59
            return '+' . $module->getDefaultFactor() . '%';
60
        }
61
        return _('Normal');
62
    }
63
64 3
    #[Override]
65
    public function calculateEvadeChance(SpacecraftRumpInterface $rump, ModuleInterface $module): int
66
    {
67 3
        $moduleLevel = $rump->getBaseValues()->getModuleLevel();
68 3
        $baseEvadeChange = $rump->getBaseValues()->getEvadeChance();
69
70 3
        if ($moduleLevel > $module->getLevel()) {
71 3
            $value = (1 - $baseEvadeChange / 100) * 1 / (1 - $module->getDowngradeFactor() / 100);
72 3
        } elseif ($moduleLevel < $module->getLevel()) {
73 3
            $value = (1 - $baseEvadeChange / 100) * 1 / (1 + $module->getUpgradeFactor() / 100);
74 3
        } elseif ($moduleLevel === $module->getLevel()) {
75 3
            $value = (1 - $baseEvadeChange / 100) * 1 / (1 + $module->getDefaultFactor() / 100);
76
        } else {
77
            return $baseEvadeChange;
78
        }
79 3
        return (int) round((1 - $value) * 100);
80
    }
81
}
82