Passed
Push — dev ( 220852...a22d66 )
by Janko
21:21
created

CallForSupportBehaviour   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A action() 0 19 1
1
<?php
2
3
namespace Stu\Lib\Pirate\Behaviour;
4
5
use Stu\Lib\Pirate\PirateBehaviourEnum;
6
use Stu\Lib\Pirate\PirateCreationInterface;
7
use Stu\Module\Ship\Lib\FleetWrapperInterface;
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 PirateLoggerInterface $logger;
16
17
    public function __construct(
18
        private PirateCreationInterface $pirateCreation,
19
        LoggerUtilFactoryInterface $loggerUtilFactory
20
    ) {
21
        $this->logger = $loggerUtilFactory->getPirateLogger();
22
    }
23
24
    public function action(FleetWrapperInterface $fleet, PirateReactionInterface $pirateReaction): ?PirateBehaviourEnum
25
    {
26
        $leadWrapper = $fleet->getLeadWrapper();
27
        $leadShip = $leadWrapper->get();
28
29
        $supportFleet = $this->pirateCreation->createPirateFleet($leadShip);
30
        $this->logger->logf(
31
            '    created support fleet %d "%s" here %s',
32
            $supportFleet->getId(),
33
            $supportFleet->getName(),
34
            $supportFleet->getLeadShip()->getSectorString()
35
        );
36
37
        $pirateReaction->react(
38
            $supportFleet,
39
            PirateReactionTriggerEnum::ON_SUPPORT_CALL
40
        );
41
42
        return null;
43
    }
44
}
45