Passed
Push — master ( bf860f...1dd8f7 )
by Nico
57:55 queued 29:36
created

PrestigeGain::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
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\Module\Message\Lib\PrivateMessageSenderInterface;
7
use Stu\Module\PlayerSetting\Lib\UserEnum;
8
use Stu\Module\Prestige\Lib\CreatePrestigeLogInterface;
9
use Stu\Module\Ship\Lib\Destruction\ShipDestroyerInterface;
10
use Stu\Module\Ship\Lib\Destruction\ShipDestructionCauseEnum;
11
use Stu\Module\Ship\Lib\ShipWrapperInterface;
12
13
class PrestigeGain implements ShipDestructionHandlerInterface
14
{
15 1
    public function __construct(
16
        private CreatePrestigeLogInterface $createPrestigeLog,
17
        private PrivateMessageSenderInterface $privateMessageSender
18
    ) {
19 1
    }
20
21
    public function handleShipDestruction(
22
        ?ShipDestroyerInterface $destroyer,
23
        ShipWrapperInterface $destroyedShipWrapper,
24
        ShipDestructionCauseEnum $cause,
25
        InformationInterface $informations
26
    ): void {
27
28
        if ($destroyer === null) {
29
            return;
30
        }
31
32
        $ship = $destroyedShipWrapper->get();
33
        $rump = $ship->getRump();
34
        $amount = $rump->getPrestige();
35
36
        // nothing to do
37
        if ($amount === 0) {
38
            return;
39
        }
40
41
        // empty escape pods to five times negative prestige
42
        if ($rump->isEscapePods() && $ship->getCrewCount() === 0) {
43
            $amount *= 5;
44
        }
45
46
        $description = sprintf(
47
            '%s%d%s Prestige erhalten für die Zerstörung von: %s',
48
            $amount < 0 ? '[b][color=red]' : '',
49
            $amount,
50
            $amount < 0 ? '[/color][/b]' : '',
51
            $rump->getName()
52
        );
53
54
        $this->createPrestigeLog->createLog($amount, $description, $destroyer->getUser(), time());
55
56
        // system pm only for negative prestige
57
        if ($amount < 0) {
58
            $this->sendSystemMessage($description, $destroyer->getUser()->getId());
59
        }
60
    }
61
62
    private function sendSystemMessage(string $description, int $userId): void
63
    {
64
        $this->privateMessageSender->send(
65
            UserEnum::USER_NOONE,
66
            $userId,
67
            $description
68
        );
69
    }
70
}
71