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

CallForSupportBehaviour   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 35
ccs 0
cts 18
cp 0
rs 10
c 2
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A action() 0 20 1
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