Passed
Push — dev ( e56e53...0dca7b )
by Janko
10:35
created

ShipUndocking::undockShip()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 14
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 18
ccs 15
cts 15
cp 1
crap 1
rs 9.7998
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Spacecraft\Lib\Interaction;
6
7
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...
8
use Stu\Component\Ship\Retrofit\CancelRetrofitInterface;
9
use Stu\Component\Spacecraft\Repair\CancelRepairInterface;
10
use Stu\Module\Message\Lib\PrivateMessageFolderTypeEnum;
11
use Stu\Module\Message\Lib\PrivateMessageSenderInterface;
12
use Stu\Orm\Entity\ShipInterface;
13
use Stu\Orm\Entity\StationInterface;
14
use Stu\Orm\Repository\ShipRepositoryInterface;
15
16
final class ShipUndocking implements ShipUndockingInterface
17
{
18 3
    public function __construct(
19
        private ShipRepositoryInterface $shipRepository,
20
        private CancelRepairInterface $cancelRepair,
21
        private CancelRetrofitInterface $cancelRetrofit,
22
        private PrivateMessageSenderInterface $privateMessageSender
23 3
    ) {}
24
25
26 1
    #[Override]
27
    public function undockShip(StationInterface $station, ShipInterface $dockedShip): void
28
    {
29 1
        $this->cancelRepair->cancelRepair($dockedShip);
30 1
        $this->cancelRetrofit->cancelRetrofit($dockedShip);
31 1
        $dockedShip->setDockedTo(null);
32 1
        $this->shipRepository->save($dockedShip);
33
34 1
        $this->privateMessageSender->send(
35 1
            $station->getUser()->getId(),
36 1
            $dockedShip->getUser()->getId(),
37 1
            sprintf(
38 1
                'Die %s wurde von der %s abgedockt',
39 1
                $dockedShip->getName(),
40 1
                $station->getName()
41 1
            ),
42 1
            PrivateMessageFolderTypeEnum::SPECIAL_SHIP,
43 1
            $dockedShip->getHref()
44 1
        );
45
    }
46
47 2
    #[Override]
48
    public function undockAllDocked(StationInterface $station): bool
49
    {
50 2
        $dockedShips = $station->getDockedShips();
51 2
        if ($dockedShips->isEmpty()) {
52 1
            return false;
53
        }
54
55 1
        foreach ($dockedShips as $dockedShip) {
56 1
            $this->undockShip($station, $dockedShip);
57
        }
58
59 1
        $dockedShips->clear();
60
61 1
        return true;
62
    }
63
}
64