Passed
Pull Request — dev (#2038)
by Janko
10:55
created

handleSpacecraftDestruction()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 3
nop 4
dl 0
loc 22
ccs 0
cts 10
cp 0
crap 20
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Spacecraft\Lib\Destruction\Handler;
4
5
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...
6
use Stu\Component\Crew\Skill\CrewEnhancemenProxy;
7
use Stu\Component\Crew\Skill\SkillEnhancementEnum;
8
use Stu\Lib\Information\InformationInterface;
9
use Stu\Module\Spacecraft\Lib\Battle\Provider\SpacecraftAttacker;
10
use Stu\Module\Spacecraft\Lib\Destruction\SpacecraftDestroyerInterface;
11
use Stu\Module\Spacecraft\Lib\Destruction\SpacecraftDestructionCauseEnum;
12
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
13
14
class EnhanceDestroyingCrew implements SpacecraftDestructionHandlerInterface
15
{
16
    #[Override]
17
    public function handleSpacecraftDestruction(
18
        ?SpacecraftDestroyerInterface $destroyer,
19
        SpacecraftWrapperInterface $destroyedSpacecraftWrapper,
20
        SpacecraftDestructionCauseEnum $cause,
21
        InformationInterface $informations
22
    ): void {
23
24
        if ($destroyer === null) {
25
            return;
26
        }
27
28
        $destroyedPrestige = $destroyedSpacecraftWrapper->get()->getRump()->getPrestige();
29
        if (
30
            $destroyedPrestige > 0
31
            && $destroyer instanceof SpacecraftAttacker
32
        ) {
33
34
            CrewEnhancemenProxy::addExpertise(
35
                $destroyer->get(),
36
                SkillEnhancementEnum::SPACECRAFT_DESTRUCTION,
37
                min(200, (int)ceil($destroyedPrestige * 100 / abs($destroyer->get()->getRump()->getPrestige())))
38
            );
39
        }
40
    }
41
}
42