Passed
Push — master ( e661f4...30021e )
by Nico
25:16 queued 10:59
created

EnergyPhalanx   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Test Coverage

Coverage 82.93%

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 112
ccs 34
cts 41
cp 0.8293
rs 10
c 0
b 0
f 0
wmc 25

18 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserId() 0 4 1
A isAvoidingHullHits() 0 4 1
A getName() 0 4 2
A getFiringMode() 0 6 1
A getHitChance() 0 4 2
A getPhaserHullDamageFactor() 0 4 1
A getPhaserShieldDamageFactor() 0 4 1
A getEps() 0 3 1
A isDisruptor() 0 3 1
A getWeaponModule() 0 13 3
A __construct() 0 1 1
A getModuleId() 0 3 2
A getPhaserState() 0 4 1
A getPhaserVolleys() 0 4 2
A hasSufficientEnergy() 0 4 1
A getLocation() 0 4 1
A getEnergyWeaponBaseDamage() 0 4 2
A reduceEps() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Spacecraft\Lib\Battle\Provider;
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\Orm\Entity\ColonyInterface;
10
use Stu\Orm\Entity\LocationInterface;
11
use Stu\Orm\Entity\ModuleInterface;
12
use Stu\Orm\Entity\SpacecraftInterface;
13
use Stu\Orm\Repository\ModuleRepositoryInterface;
14
15
final class EnergyPhalanx extends AbstractEnergyAttacker
16
{
17 24
    public function __construct(private ColonyInterface $colony, private ModuleRepositoryInterface $moduleRepository) {}
18
19 2
    #[Override]
20
    public function hasSufficientEnergy(int $amount): bool
21
    {
22 2
        return $this->getEps() >= $amount;
23
    }
24
25
    #[Override]
26
    public function isAvoidingHullHits(SpacecraftInterface $target): bool
27
    {
28
        return false;
29
    }
30
31
    #[Override]
32
    public function getFiringMode(): int
33
    {
34
        $weapon = $this->getWeapon();
35
36
        return $weapon->getFiringMode();
37
    }
38
39 3
    private function getEps(): int
40
    {
41 3
        return $this->colony->getEps();
42
    }
43
44 1
    #[Override]
45
    public function reduceEps(int $amount): void
46
    {
47 1
        $this->colony->setEps($this->getEps() - $amount);
48
    }
49
50 1
    #[Override]
51
    public function getUserId(): int
52
    {
53 1
        return $this->colony->getUser()->getId();
54
    }
55
56 16
    private function isDisruptor(): bool
57
    {
58 16
        return in_array($this->colony->getUser()->getFactionId(), [2, 3]);
59
    }
60
61 3
    #[Override]
62
    public function getName(): string
63
    {
64 3
        return $this->isDisruptor() ? 'Orbitale Disruptorphalanx' : 'Orbitale Phaserphalanx';
65
    }
66
67 1
    #[Override]
68
    public function getPhaserState(): bool
69
    {
70 1
        return true;
71
    }
72
73 3
    #[Override]
74
    public function getHitChance(): int
75
    {
76 3
        return $this->isDisruptor() ? 67 : 86;
77
    }
78
79 4
    private function getModuleId(): int
80
    {
81 4
        return $this->isDisruptor() ? 3 : 1;
82
    }
83
84 4
    #[Override]
85
    public function getWeaponModule(): ModuleInterface
86
    {
87 4
        if ($this->module === null) {
88 4
            $module = $this->moduleRepository->find($this->getModuleId());
89 4
            if ($module === null) {
90 1
                throw new RuntimeException('module not existent');
91
            }
92
93 3
            $this->module = $module;
94
        }
95
96 3
        return $this->module;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->module could return the type null which is incompatible with the type-hinted return Stu\Orm\Entity\ModuleInterface. Consider adding an additional type-check to rule them out.
Loading history...
97
    }
98
99 3
    #[Override]
100
    public function getEnergyWeaponBaseDamage(): int
101
    {
102 3
        return $this->isDisruptor() ? 180 : 250;
103
    }
104
105 3
    #[Override]
106
    public function getPhaserVolleys(): int
107
    {
108 3
        return $this->isDisruptor() ? 5 : 3;
109
    }
110
111 1
    #[Override]
112
    public function getPhaserShieldDamageFactor(): int
113
    {
114 1
        return 200;
115
    }
116
117 1
    #[Override]
118
    public function getPhaserHullDamageFactor(): int
119
    {
120 1
        return 100;
121
    }
122
123
    #[Override]
124
    public function getLocation(): LocationInterface
125
    {
126
        return $this->colony->getLocation();
127
    }
128
}
129