Passed
Push — dev ( 83c248...96a6f5 )
by Janko
10:53
created

EnergyPhalanx::getUserId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Repository\ModuleRepositoryInterface;
13
14
final class EnergyPhalanx extends AbstractEnergyAttacker
15
{
16 24
    public function __construct(private ColonyInterface $colony, private ModuleRepositoryInterface $moduleRepository) {}
17
18 2
    #[Override]
19
    public function hasSufficientEnergy(int $amount): bool
20
    {
21 2
        return $this->getEps() >= $amount;
22
    }
23
24
    #[Override]
25
    public function getFiringMode(): int
26
    {
27
        $weapon = $this->getWeapon();
28
29
        return $weapon->getFiringMode();
30
    }
31
32 3
    private function getEps(): int
33
    {
34 3
        return $this->colony->getEps();
35
    }
36
37 1
    #[Override]
38
    public function reduceEps(int $amount): void
39
    {
40 1
        $this->colony->setEps($this->getEps() - $amount);
41
    }
42
43 1
    #[Override]
44
    public function getUserId(): int
45
    {
46 1
        return $this->colony->getUser()->getId();
47
    }
48
49 16
    private function isDisruptor(): bool
50
    {
51 16
        return in_array($this->colony->getUser()->getFactionId(), [2, 3]);
52
    }
53
54 3
    #[Override]
55
    public function getName(): string
56
    {
57 3
        return $this->isDisruptor() ? 'Orbitale Disruptorphalanx' : 'Orbitale Phaserphalanx';
58
    }
59
60 1
    #[Override]
61
    public function getPhaserState(): bool
62
    {
63 1
        return true;
64
    }
65
66 3
    #[Override]
67
    public function getHitChance(): int
68
    {
69 3
        return $this->isDisruptor() ? 67 : 86;
70
    }
71
72 4
    private function getModuleId(): int
73
    {
74 4
        return $this->isDisruptor() ? 3 : 1;
75
    }
76
77 4
    #[Override]
78
    public function getWeaponModule(): ModuleInterface
79
    {
80 4
        if ($this->module === null) {
81 4
            $module = $this->moduleRepository->find($this->getModuleId());
82 4
            if ($module === null) {
83 1
                throw new RuntimeException('module not existent');
84
            }
85
86 3
            $this->module = $module;
87
        }
88
89 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...
90
    }
91
92 3
    #[Override]
93
    public function getEnergyWeaponBaseDamage(): int
94
    {
95 3
        return $this->isDisruptor() ? 180 : 250;
96
    }
97
98 3
    #[Override]
99
    public function getPhaserVolleys(): int
100
    {
101 3
        return $this->isDisruptor() ? 5 : 3;
102
    }
103
104 1
    #[Override]
105
    public function getPhaserShieldDamageFactor(): int
106
    {
107 1
        return 200;
108
    }
109
110 1
    #[Override]
111
    public function getPhaserHullDamageFactor(): int
112
    {
113 1
        return 100;
114
    }
115
116
    #[Override]
117
    public function getLocation(): LocationInterface
118
    {
119
        return $this->colony->getLocation();
120
    }
121
}
122