Passed
Push — dev ( 45bf8d...5b8f46 )
by Janko
10:07
created

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