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

DockConsequence   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 17
dl 0
loc 33
ccs 14
cts 16
cp 0.875
rs 10
c 1
b 1
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A triggerSpecific() 0 27 5
A __construct() 0 3 1
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
}