Passed
Push — dev ( 83f1db...78efa3 )
by Janko
43:47 queued 20:47
created

CallForSupportBehaviour::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Stu\Lib\Pirate\Behaviour;
4
5
use Stu\Lib\Pirate\PirateBehaviourEnum;
6
use Stu\Module\Ship\Lib\FleetWrapperInterface;
7
use Stu\Lib\Pirate\PirateCreationInterface;
8
use Stu\Lib\Pirate\PirateReactionInterface;
9
use Stu\Lib\Pirate\PirateReactionTriggerEnum;
10
use Stu\Module\Logging\LoggerUtilFactoryInterface;
11
use Stu\Module\Logging\PirateLoggerInterface;
12
13
class CallForSupportBehaviour implements PirateBehaviourInterface
14
{
15
    private PirateCreationInterface $pirateCreation;
16
17
    private PirateLoggerInterface $logger;
18
19
    public function __construct(
20
        PirateCreationInterface $pirateCreation,
21
        LoggerUtilFactoryInterface $loggerUtilFactory
22
    ) {
23
        $this->pirateCreation = $pirateCreation;
24
25
        $this->logger = $loggerUtilFactory->getPirateLogger();
26
    }
27
28
    public function action(FleetWrapperInterface $fleet, PirateReactionInterface $pirateReaction): ?PirateBehaviourEnum
29
    {
30
        $leadWrapper = $fleet->getLeadWrapper();
31
        $leadShip = $leadWrapper->get();
32
33
        $supportFleet = $this->pirateCreation->createPirateFleet($leadShip);
34
35
        $this->logger->logf(
36
            '    created support fleet %d "%s" here %s',
37
            $supportFleet->getId(),
38
            $supportFleet->getName(),
39
            $supportFleet->getLeadShip()->getSectorString()
40
        );
41
42
        $pirateReaction->react(
43
            $supportFleet,
44
            PirateReactionTriggerEnum::ON_SUPPORT_CALL
45
        );
46
47
        return null;
48
    }
49
}
50