Passed
Push — dev ( 80c162...225d4f )
by Janko
09:12
created

TholianWebDestruction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 4
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
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\Spacecraft\Lib\Destruction\SpacecraftDestroyerInterface;
9
use Stu\Module\Spacecraft\Lib\Destruction\SpacecraftDestructionCauseEnum;
10
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperFactoryInterface;
11
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
12
use Stu\Orm\Entity\ShipInterface;
13
use Stu\Orm\Entity\TholianWebInterface;
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 1
    public function __construct(
21
        private TholianWebRepositoryInterface $tholianWebRepository,
22
        private SpacecraftSystemRepositoryInterface $spacecraftSystemRepository,
23
        private SpacecraftRepositoryInterface $spacecraftRepository,
24
        private SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory
25 1
    ) {}
26
27
    #[Override]
28
    public function handleSpacecraftDestruction(
29
        ?SpacecraftDestroyerInterface $destroyer,
30
        SpacecraftWrapperInterface $destroyedSpacecraftWrapper,
31
        SpacecraftDestructionCauseEnum $cause,
32
        InformationInterface $informations,
33
    ): void {
34
35
        $tholianWeb = $destroyedSpacecraftWrapper->get();
36
        if (!$tholianWeb instanceof TholianWebInterface) {
37
            return;
38
        }
39
40
        foreach ($tholianWeb->getCapturedSpacecrafts() as $spacecraft) {
41
            $spacecraft->setHoldingWeb(null);
42
            $this->spacecraftRepository->save($spacecraft);
43
        }
44
45
        $owningSpacecraftSystem = $this->spacecraftSystemRepository->getWebOwningShipSystem($tholianWeb->getId());
46
        if ($owningSpacecraftSystem === null) {
47
            return;
48
        }
49
50
        /** @var ShipInterface */
51
        $owningShip = $owningSpacecraftSystem->getSpacecraft();
52
53
        $webEmitterSystemData = $this->spacecraftWrapperFactory
54
            ->wrapShip($owningShip)
55
            ->getWebEmitterSystemData();
56
57
        if ($webEmitterSystemData === null) {
58
            throw new RuntimeException('this should not happen');
59
        }
60
61
        $webEmitterSystemData->setOwnedWebId(null)
62
            ->update();
63
64
        $this->tholianWebRepository->delete($tholianWeb);
65
    }
66
}
67