Test Failed
Push — dev ( 4abd48...6c393a )
by Janko
09:10
created

TholianWebDestruction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 4
dl 0
loc 6
rs 10
c 1
b 1
f 0
1
<?php
2
3
namespace Stu\Module\Spacecraft\Lib\Destruction\Handler;
4
5
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use RuntimeException;
7
use Stu\Lib\Information\InformationInterface;
8
use Stu\Module\Ship\Lib\ShipWrapperInterface;
9
use Stu\Module\Spacecraft\Lib\Destruction\SpacecraftDestroyerInterface;
10
use Stu\Module\Spacecraft\Lib\Destruction\SpacecraftDestructionCauseEnum;
11
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperFactoryInterface;
12
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
13
use Stu\Orm\Entity\ShipInterface;
14
use Stu\Orm\Repository\SpacecraftRepositoryInterface;
15
use Stu\Orm\Repository\SpacecraftSystemRepositoryInterface;
16
use Stu\Orm\Repository\TholianWebRepositoryInterface;
17
18
class TholianWebDestruction implements SpacecraftDestructionHandlerInterface
19
{
20
    public function __construct(
21
        private TholianWebRepositoryInterface $tholianWebRepository,
22
        private SpacecraftSystemRepositoryInterface $spacecraftSystemRepository,
23
        private SpacecraftRepositoryInterface $spacecraftRepository,
24
        private SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory
25
    ) {}
26
27
    #[Override]
28
    public function handleSpacecraftDestruction(
29
        ?SpacecraftDestroyerInterface $destroyer,
30
        SpacecraftWrapperInterface $destroyedSpacecraftWrapper,
31
        SpacecraftDestructionCauseEnum $cause,
32
        InformationInterface $informations,
33
    ): void {
34
35
        if (!$destroyedSpacecraftWrapper instanceof ShipWrapperInterface) {
36
            return;
37
        }
38
39
        $tholianWeb = $destroyedSpacecraftWrapper->get()->getTholianWeb();
40
        if ($tholianWeb === null) {
41
            return;
42
        }
43
44
        foreach ($tholianWeb->getCapturedShips() as $ship) {
45
            $ship->setHoldingWeb(null);
46
            $this->spacecraftRepository->save($ship);
47
        }
48
49
        $owningSpacecraftSystem = $this->spacecraftSystemRepository->getWebOwningShipSystem($tholianWeb->getId());
50
        if ($owningSpacecraftSystem === null) {
51
            return;
52
        }
53
54
        /** @var ShipInterface */
55
        $owningShip = $owningSpacecraftSystem->getSpacecraft();
56
57
        $webEmitterSystemData = $this->spacecraftWrapperFactory
58
            ->wrapShip($owningShip)
59
            ->getWebEmitterSystemData();
60
61
        if ($webEmitterSystemData === null) {
62
            throw new RuntimeException('this should not happen');
63
        }
64
65
        $webEmitterSystemData->setOwnedWebId(null)
66
            ->update();
67
68
        $this->tholianWebRepository->delete($tholianWeb);
69
    }
70
}
71