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

ResetTrackerDevices   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 28.57%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 22
ccs 2
cts 7
cp 0.2857
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleShipDestruction() 0 13 2
A __construct() 0 5 1
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\Ship\Lib\Destruction\ShipDestroyerInterface;
9
use Stu\Module\Ship\Lib\Destruction\ShipDestructionCauseEnum;
10
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface;
11
use Stu\Module\Ship\Lib\ShipWrapperInterface;
12
use Stu\Orm\Repository\ShipSystemRepositoryInterface;
13
14
class ResetTrackerDevices implements ShipDestructionHandlerInterface
15
{
16 1
    public function __construct(
17
        private ShipSystemRepositoryInterface $shipSystemRepository,
18
        private ShipSystemManagerInterface $shipSystemManager,
19
        private ShipWrapperFactoryInterface $shipWrapperFactory
20
    ) {
21 1
    }
22
23
    public function handleShipDestruction(
24
        ?ShipDestroyerInterface $destroyer,
25
        ShipWrapperInterface $destroyedShipWrapper,
26
        ShipDestructionCauseEnum $cause,
27
        InformationInterface $informations
28
    ): void {
29
30
        $shipId = $destroyedShipWrapper->get()->getId();
31
32
        foreach ($this->shipSystemRepository->getTrackingShipSystems($shipId) as $system) {
33
            $wrapper = $this->shipWrapperFactory->wrapShip($system->getShip());
34
35
            $this->shipSystemManager->deactivate($wrapper, ShipSystemTypeEnum::SYSTEM_TRACKER, true);
36
        }
37
    }
38
}
39