Passed
Pull Request — master (#2112)
by Janko
10:38
created

ForeignCrewDumpingHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Player\Deletion\Handler;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
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...
9
use Stu\Module\Spacecraft\Lib\Crew\SpacecraftLeaverInterface;
10
use Stu\Orm\Entity\UserInterface;
11
use Stu\Orm\Repository\StationRepositoryInterface;
12
13
final class ForeignCrewDumpingHandler implements PlayerDeletionHandlerInterface
14
{
15 2
    public function __construct(
16
        private StationRepositoryInterface $stationRepository,
17
        private SpacecraftLeaverInterface $spacecraftLeaver,
18
        private EntityManagerInterface $entityManager
19 2
    ) {}
20
21 1
    #[Override]
22
    public function delete(UserInterface $user): void
23
    {
24 1
        foreach ($this->stationRepository->getStationsByUser($user->getId()) as $station) {
25
26 1
            foreach ($station->getCrewAssignments() as $crewAssignment) {
27
28 1
                $crew = $crewAssignment->getCrew();
29 1
                if ($crew->getUser() === $station->getUser()) {
30 1
                    continue;
31
                }
32
33 1
                $this->spacecraftLeaver->dumpCrewman(
34 1
                    $crewAssignment,
35 1
                    sprintf(
36 1
                        'Die Dienste von Crewman %s werden nicht mehr auf der Station %s von Spieler %s benötigt.',
37 1
                        $crew->getName(),
38 1
                        $station->getName(),
39 1
                        $station->getUser()->getName(),
40 1
                    )
41 1
                );
42
43 1
                $this->entityManager->detach($crewAssignment);
44 1
                $this->entityManager->detach($crew);
45
            }
46
        }
47
    }
48
}
49