Passed
Pull Request — master (#1969)
by Janko
22:34 queued 10:03
created

AbstractEnergyAttacker::getFiringMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 3
cp 0
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 RuntimeException;
9
use Stu\Orm\Entity\ModuleInterface;
10
use Stu\Orm\Entity\WeaponInterface;
11
12
abstract class AbstractEnergyAttacker implements EnergyAttackerInterface
13
{
14
    protected ?ModuleInterface $module = null;
15
    private ?WeaponInterface $weapon = null;
16
17
    #[Override]
18
    public function getFiringMode(): int
19
    {
20
        $weapon = $this->getWeapon();
21
22
        return $weapon->getFiringMode();
23
    }
24
25
    abstract public function getWeaponModule(): ModuleInterface;
26
27
    #[Override]
28
    public function getWeapon(): WeaponInterface
29
    {
30
        if ($this->weapon === null) {
31
            $weapon = $this->getWeaponModule()->getWeapon();
32
            if ($weapon === null) {
33
                throw new RuntimeException('module system should have a weapon');
34
            }
35
36
            $this->weapon = $weapon;
37
        }
38
39
        return $this->weapon;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->weapon could return the type null which is incompatible with the type-hinted return Stu\Orm\Entity\WeaponInterface. Consider adding an additional type-check to rule them out.
Loading history...
40
    }
41
42
    abstract public function getEnergyWeaponBaseDamage(): int;
43
44
    #[Override]
45
    public function getWeaponDamage(bool $isCritical): int
46
    {
47
        $basedamage = $this->getEnergyWeaponBaseDamage();
48
        $variance = (int) round($basedamage / 100 * $this->getWeapon()->getVariance());
49
        $damage = random_int($basedamage - $variance, $basedamage + $variance);
50
51
        return $isCritical ? $damage * 2 : $damage;
52
    }
53
}
54