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

ProjectilePhalanx::lowerTorpedoCount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

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