Passed
Push — master ( 0a21cd...0ad97c )
by Janko
05:01
created

TractorConsequence::triggerSpecific()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 3
dl 0
loc 21
ccs 10
cts 10
cp 1
crap 3
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Spacecraft\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\Component\Spacecraft\System\Utility\TractorMassPayloadUtilInterface;
9
use Stu\Module\Ship\Lib\CancelColonyBlockOrDefendInterface;
10
use Stu\Module\Spacecraft\Lib\Message\MessageCollectionInterface;
11
use Stu\Module\Spacecraft\Lib\Message\MessageFactoryInterface;
12
use Stu\Module\Spacecraft\Lib\Movement\Component\Consequence\AbstractFlightConsequence;
13
use Stu\Module\Spacecraft\Lib\Movement\Route\FlightRouteInterface;
14
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
15
16
class TractorConsequence extends AbstractFlightConsequence implements FlightStartConsequenceInterface
17
{
18 4
    public function __construct(
19
        private TractorMassPayloadUtilInterface $tractorMassPayloadUtil,
20
        private CancelColonyBlockOrDefendInterface $cancelColonyBlockOrDefend,
21
        private MessageFactoryInterface $messageFactory
22 4
    ) {}
23
24 6
    #[Override]
25
    protected function skipWhenTractored(): bool
26
    {
27 6
        return true;
28
    }
29
30 6
    #[Override]
31
    protected function triggerSpecific(
32
        SpacecraftWrapperInterface $wrapper,
33
        FlightRouteInterface $flightRoute,
34
        MessageCollectionInterface $messages
35
    ): void {
36
37 6
        $ship = $wrapper->get();
38
39 6
        $tractoredShip = $ship->getTractoredShip();
40 6
        if ($tractoredShip === null) {
41 4
            return;
42
        }
43
44 2
        $message = $this->messageFactory->createMessage();
45 2
        $messages->add($message);
46
47
        //can tow tractored ship?
48 2
        $canTowTractoredShip = $this->tractorMassPayloadUtil->tryToTow($wrapper, $tractoredShip, $message);
49 2
        if ($canTowTractoredShip) {
50 1
            $this->cancelColonyBlockOrDefend->work($ship, $message, true);
51
        }
52
    }
53
}
54