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

ClearTractoringBeam   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 11.11%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 32
ccs 2
cts 18
cp 0.1111
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handleShipDestruction() 0 24 3
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