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

ColonizationShipCheck   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 28.57%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 19
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 12 2
A __construct() 0 3 1
1
<?php
2
3
namespace Stu\Module\Ship\Lib\Destruction\Handler;
4
5
use Stu\Lib\Information\InformationInterface;
6
use Stu\Module\PlayerSetting\Lib\UserEnum;
7
use Stu\Module\Ship\Lib\Destruction\ShipDestroyerInterface;
8
use Stu\Module\Ship\Lib\Destruction\ShipDestructionCauseEnum;
9
use Stu\Module\Ship\Lib\ShipWrapperInterface;
10
use Stu\Orm\Repository\UserRepositoryInterface;
11
12
class ColonizationShipCheck implements ShipDestructionHandlerInterface
13
{
14 1
    public function __construct(
15
        private UserRepositoryInterface $userRepository
16
    ) {
17 1
    }
18
19
    public function handleShipDestruction(
20
        ?ShipDestroyerInterface $destroyer,
21
        ShipWrapperInterface $destroyedShipWrapper,
22
        ShipDestructionCauseEnum $cause,
23
        InformationInterface $informations
24
    ): void {
25
26
        $user = $destroyedShipWrapper->get()->getUser();
27
28
        if ($user->getState() === UserEnum::USER_STATE_COLONIZATION_SHIP) {
29
            $user->setState(UserEnum::USER_STATE_UNCOLONIZED);
30
            $this->userRepository->save($user);
31
        }
32
    }
33
}
34