Passed
Push — dev ( c878e4...99122a )
by Janko
30:05
created

UpdatePirateWrath::handleShipDestruction()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
nc 6
nop 4
dl 0
loc 26
ccs 0
cts 13
cp 0
crap 30
rs 9.5555
c 1
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Ship\Lib\Destruction\Handler;
4
5
use Stu\Lib\Information\InformationInterface;
6
use Stu\Lib\Pirate\Component\PirateWrathManagerInterface;
7
use Stu\Module\PlayerSetting\Lib\UserEnum;
8
use Stu\Module\Ship\Lib\Destruction\ShipDestroyerInterface;
9
use Stu\Module\Ship\Lib\Destruction\ShipDestructionCauseEnum;
10
use Stu\Module\Ship\Lib\ShipWrapperInterface;
11
12
class UpdatePirateWrath
13
{
14 1
    public function __construct(
15
        private PirateWrathManagerInterface $pirateWrathManager
16
    ) {
17 1
    }
18
19
    public function handleShipDestruction(
20
        ?ShipDestroyerInterface $destroyer,
21
        ShipWrapperInterface $destroyedShipWrapper,
22
        ShipDestructionCauseEnum $cause,
0 ignored issues
show
Unused Code introduced by
The parameter $cause is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

22
        /** @scrutinizer ignore-unused */ ShipDestructionCauseEnum $cause,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
        InformationInterface $informations
0 ignored issues
show
Unused Code introduced by
The parameter $informations is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
        /** @scrutinizer ignore-unused */ InformationInterface $informations

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    ): void {
25
26
        if ($destroyer === null) {
27
            return;
28
        }
29
30
        $ship = $destroyedShipWrapper->get();
31
        $targetPrestige = $ship->getRump()->getPrestige();
32
        if ($targetPrestige < 1) {
33
            return;
34
        }
35
36
        $destroyerUser = $destroyer->getUser();
37
        $userOfDestroyed = $destroyedShipWrapper->get()->getUser();
38
39
        if ($destroyerUser->getId() === UserEnum::USER_NPC_KAZON) {
40
            $this->pirateWrathManager->decreaseWrath($userOfDestroyed, $targetPrestige);
41
        }
42
43
        if ($userOfDestroyed->getId() === UserEnum::USER_NPC_KAZON) {
44
            $this->pirateWrathManager->increaseWrath($userOfDestroyed, $targetPrestige);
45
        }
46
    }
47
}
48