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

ClearTractoringBeam::handleShipDestruction()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 14
nc 2
nop 4
dl 0
loc 24
ccs 0
cts 16
cp 0
crap 12
rs 9.7998
c 1
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Ship\Lib\Destruction\Handler;
4
5
use Stu\Component\Ship\System\ShipSystemManagerInterface;
6
use Stu\Component\Ship\System\ShipSystemTypeEnum;
7
use Stu\Lib\Information\InformationInterface;
8
use Stu\Module\Message\Lib\PrivateMessageFolderSpecialEnum;
9
use Stu\Module\Message\Lib\PrivateMessageSenderInterface;
10
use Stu\Module\PlayerSetting\Lib\UserEnum;
11
use Stu\Module\Ship\Lib\Destruction\ShipDestroyerInterface;
12
use Stu\Module\Ship\Lib\Destruction\ShipDestructionCauseEnum;
13
use Stu\Module\Ship\Lib\ShipWrapperInterface;
14
use Stu\Module\Ship\View\ShowShip\ShowShip;
15
16
class ClearTractoringBeam implements ShipDestructionHandlerInterface
17
{
18 1
    public function __construct(
19
        private ShipSystemManagerInterface $shipSystemManager,
20
        private PrivateMessageSenderInterface $privateMessageSender
21
    ) {
22 1
    }
23
24
    public function handleShipDestruction(
25
        ?ShipDestroyerInterface $destroyer,
26
        ShipWrapperInterface $destroyedShipWrapper,
27
        ShipDestructionCauseEnum $cause,
28
        InformationInterface $informations
29
    ): void {
30
31
        $tractoringShipWrapper = $destroyedShipWrapper->getTractoringShipWrapper();
32
        if ($tractoringShipWrapper !== null) {
33
            $tractoringShip = $tractoringShipWrapper->get();
34
            $this->shipSystemManager->deactivate($tractoringShipWrapper, ShipSystemTypeEnum::SYSTEM_TRACTOR_BEAM, true);
35
36
            $href = sprintf('ship.php?%s=1&id=%d', ShowShip::VIEW_IDENTIFIER, $tractoringShip->getId());
37
38
            $this->privateMessageSender->send(
39
                UserEnum::USER_NOONE,
40
                $tractoringShip->getUser()->getId(),
41
                sprintf(
42
                    'Die im Traktorstrahl der %s befindliche %s wurde zerstört',
43
                    $tractoringShip->getName(),
44
                    $destroyedShipWrapper->get()->getName()
45
                ),
46
                $tractoringShip->isBase() ? PrivateMessageFolderSpecialEnum::PM_SPECIAL_STATION : PrivateMessageFolderSpecialEnum::PM_SPECIAL_SHIP,
47
                $href
48
            );
49
        }
50
    }
51
}
52