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

ProjectilePhalanx::getEps()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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 Stu\Lib\Transfer\Storage\StorageManagerInterface;
9
use Stu\Orm\Entity\ColonyInterface;
10
use Stu\Orm\Entity\LocationInterface;
11
use Stu\Orm\Entity\SpacecraftInterface;
12
use Stu\Orm\Entity\TorpedoTypeInterface;
13
14
final class ProjectilePhalanx implements ProjectileAttackerInterface
15
{
16 17
    public function __construct(
17
        private ColonyInterface $colony,
18
        private StorageManagerInterface $storageManager
19 17
    ) {}
20
21 2
    #[Override]
22
    public function hasSufficientEnergy(int $amount): bool
23
    {
24 2
        return $this->getEps() >= $amount;
25
    }
26
27
    #[Override]
28
    public function isAvoidingHullHits(SpacecraftInterface $target): bool
29
    {
30
        return false;
31
    }
32
33 3
    private function getEps(): int
34
    {
35 3
        return $this->colony->getEps();
36
    }
37
38 1
    #[Override]
39
    public function reduceEps(int $amount): void
40
    {
41 1
        $this->colony->setEps($this->getEps() - $amount);
42
    }
43
44 1
    #[Override]
45
    public function getName(): string
46
    {
47 1
        return 'Orbitale Torpedophalanx';
48
    }
49
50 2
    #[Override]
51
    public function getTorpedoState(): bool
52
    {
53 2
        return $this->getTorpedoCount() > 0;
54
    }
55
56 1
    #[Override]
57
    public function getHitChance(): int
58
    {
59 1
        return 75;
60
    }
61
62 1
    #[Override]
63
    public function getUserId(): int
64
    {
65 1
        return $this->colony->getUser()->getId();
66
    }
67
68 5
    #[Override]
69
    public function getTorpedoCount(): int
70
    {
71 5
        $torpedo = $this->getTorpedo();
72
73 5
        if ($torpedo != null) {
74 4
            $stor = $this->colony->getStorage()->get($torpedo->getCommodityId());
75
76 4
            if ($stor !== null) {
77 3
                return $stor->getAmount();
78
            }
79
        }
80
81 2
        return  0;
82
    }
83
84 2
    #[Override]
85
    public function lowerTorpedoCount(int $amount): void
86
    {
87 2
        $torpedo = $this->getTorpedo();
88 2
        if ($torpedo === null) {
89 1
            return;
90
        }
91
92 1
        $this->storageManager->lowerStorage(
93 1
            $this->colony,
94 1
            $torpedo->getCommodity(),
95 1
            $amount
96 1
        );
97
    }
98
99
    #[Override]
100
    public function isShieldPenetration(): bool
101
    {
102
        return false;
103
    }
104
105 9
    #[Override]
106
    public function getTorpedo(): ?TorpedoTypeInterface
107
    {
108 9
        return $this->colony->getTorpedo();
109
    }
110
111 1
    #[Override]
112
    public function getTorpedoVolleys(): int
113
    {
114 1
        return 7;
115
    }
116
117 2
    #[Override]
118
    public function getProjectileWeaponDamage(bool $isCritical): int
119
    {
120 2
        $torpedo = $this->getTorpedo();
121 2
        if ($torpedo === null) {
122 1
            return 0;
123
        }
124
125 1
        $basedamage = $torpedo->getBaseDamage();
126 1
        $variance = (int) round($basedamage / 100 * $torpedo->getVariance());
127 1
        $damage = random_int($basedamage - $variance, $basedamage + $variance);
128
129 1
        return $isCritical ? $damage * 2 : $damage;
130
    }
131
132
    #[Override]
133
    public function getLocation(): LocationInterface
134
    {
135
        return $this->colony->getLocation();
136
    }
137
}
138