Passed
Push — dev ( 0aa780...31f66c )
by Janko
11:20
created

TholianWebDestruction   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 9.09%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 21
dl 0
loc 50
ccs 2
cts 22
cp 0.0909
rs 10
c 1
b 1
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A handleSpacecraftDestruction() 0 40 5
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\TholianWebUtilInterface;
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\Entity\TholianWebInterface;
15
use Stu\Orm\Repository\SpacecraftRepositoryInterface;
16
use Stu\Orm\Repository\SpacecraftSystemRepositoryInterface;
17
use Stu\Orm\Repository\TholianWebRepositoryInterface;
18
19
class TholianWebDestruction implements SpacecraftDestructionHandlerInterface
20
{
21 1
    public function __construct(
22
        private TholianWebRepositoryInterface $tholianWebRepository,
23
        private SpacecraftSystemRepositoryInterface $spacecraftSystemRepository,
24
        private SpacecraftRepositoryInterface $spacecraftRepository,
25
        private SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory,
26
        private TholianWebUtilInterface $tholianWebUtil
27 1
    ) {}
28
29
    #[Override]
30
    public function handleSpacecraftDestruction(
31
        ?SpacecraftDestroyerInterface $destroyer,
32
        SpacecraftWrapperInterface $destroyedSpacecraftWrapper,
33
        SpacecraftDestructionCauseEnum $cause,
34
        InformationInterface $informations,
35
    ): void {
36
37
        $tholianWeb = $destroyedSpacecraftWrapper->get();
38
        if (!$tholianWeb instanceof TholianWebInterface) {
39
            return;
40
        }
41
42
        foreach ($tholianWeb->getCapturedSpacecrafts() as $spacecraft) {
43
            $spacecraft->setHoldingWeb(null);
44
            $this->spacecraftRepository->save($spacecraft);
45
        }
46
47
        $owningSpacecraftSystem = $this->spacecraftSystemRepository->getWebOwningShipSystem($tholianWeb->getId());
48
        if ($owningSpacecraftSystem === null) {
49
            return;
50
        }
51
52
        $this->tholianWebUtil->resetWebHelpers($tholianWeb, $this->spacecraftWrapperFactory);
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