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

OrphanizeStorage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 18
ccs 2
cts 6
cp 0.3333
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handleShipDestruction() 0 10 2
1
<?php
2
3
namespace Stu\Module\Ship\Lib\Destruction\Handler;
4
5
use Stu\Lib\Information\InformationInterface;
6
use Stu\Module\Ship\Lib\Destruction\ShipDestroyerInterface;
7
use Stu\Module\Ship\Lib\Destruction\ShipDestructionCauseEnum;
8
use Stu\Module\Ship\Lib\ShipWrapperInterface;
9
use Stu\Orm\Repository\StorageRepositoryInterface;
10
use Stu\Orm\Repository\UserRepositoryInterface;
11
12
class OrphanizeStorage implements ShipDestructionHandlerInterface
13
{
14 1
    public function __construct(
15
        private UserRepositoryInterface $userRepository,
16
        private StorageRepositoryInterface $storageRepository
17
    ) {
18 1
    }
19
20
    public function handleShipDestruction(
21
        ?ShipDestroyerInterface $destroyer,
22
        ShipWrapperInterface $destroyedShipWrapper,
23
        ShipDestructionCauseEnum $cause,
24
        InformationInterface $informations
25
    ): void {
26
27
        foreach ($destroyedShipWrapper->get()->getStorage() as $storage) {
28
            $storage->setUser($this->userRepository->getFallbackUser());
29
            $this->storageRepository->save($storage);
30
        }
31
    }
32
}
33