Passed
Push — master ( 15d483...fbd3ae )
by Nico
31:54 queued 02:53
created

DockConsequence::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
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 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib\Movement\Component\Consequence\Flight;
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\Module\Ship\Lib\Message\MessageCollectionInterface;
9
use Stu\Module\Ship\Lib\Message\MessageFactoryInterface;
10
use Stu\Module\Ship\Lib\Movement\Component\Consequence\AbstractFlightConsequence;
11
use Stu\Module\Ship\Lib\Movement\Route\FlightRouteInterface;
12
use Stu\Module\Ship\Lib\ShipWrapperInterface;
13
use Stu\Component\Ship\ShipEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Ship\ShipEnum 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...
14
15
class DockConsequence extends AbstractFlightConsequence
16
{
17 5
    public function __construct(
18
        private MessageFactoryInterface $messageFactory
19 5
    ) {}
20
21 3
    #[Override]
22
    protected function triggerSpecific(
23
        ShipWrapperInterface $wrapper,
24
        FlightRouteInterface $flightRoute,
25
        MessageCollectionInterface $messages
26
    ): void {
27
28 3
        $ship = $wrapper->get();
29
30 3
        if ($ship->getDockedTo() !== null) {
31
32 2
            $message = $this->messageFactory->createMessage(null, $ship->getUser()->getId());
33 2
            $messages->add($message);
34 2
            $epsSystem = $wrapper->getEpsSystemData();
35 2
            if ($epsSystem === null || $epsSystem->getEps() < ShipEnum::SYSTEM_ECOST_DOCK) {
36
                $message->add(sprintf('%s konnte wegen Energiemangels nicht abgedockt werden', $ship->getName()));
37
                return;
38
            } else {
39 2
                $epsSystem->lowerEps(ShipEnum::SYSTEM_ECOST_DOCK)->update();
40 2
                $ship->setDockedTo(null);
41
            }
42
43 2
            if ($ship->isTractored()) {
44
                //TODO andockschleuse schrotten, wenn passiv
45 1
                $message->add(sprintf('Die %s wurde abgedockt', $ship->getName()));
46
            } else {
47 1
                $message->add(sprintf('Die %s wurde abgedockt', $ship->getName()));
48
            }
49
        }
50
    }
51
}