Passed
Push — dev ( 8eb724...1b48e4 )
by Janko
09:40
created

HideBehaviour   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 16.66%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 34
ccs 2
cts 12
cp 0.1666
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A action() 0 22 2
1
<?php
2
3
namespace Stu\Lib\Pirate\Behaviour;
4
5
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...
6
use Stu\Lib\Pirate\Component\PirateNavigationInterface;
7
use Stu\Lib\Pirate\PirateBehaviourEnum;
8
use Stu\Lib\Pirate\PirateReactionInterface;
9
use Stu\Lib\Pirate\PirateReactionMetadata;
10
use Stu\Module\Logging\LoggerUtilFactoryInterface;
11
use Stu\Module\Logging\PirateLoggerInterface;
12
use Stu\Module\Ship\Lib\FleetWrapperInterface;
13
use Stu\Orm\Entity\SpacecraftInterface;
14
use Stu\Orm\Repository\StarSystemRepositoryInterface;
15
16
class HideBehaviour implements PirateBehaviourInterface
17
{
18
    private PirateLoggerInterface $logger;
19
20 1
    public function __construct(
21
        private StarSystemRepositoryInterface $starSystemRepository,
22
        private PirateNavigationInterface $pirateNavigation,
23
        LoggerUtilFactoryInterface $loggerUtilFactory
24
    ) {
25 1
        $this->logger = $loggerUtilFactory->getPirateLogger();
26
    }
27
28
    #[Override]
29
    public function action(
30
        FleetWrapperInterface $fleet,
31
        PirateReactionInterface $pirateReaction,
32
        PirateReactionMetadata $reactionMetadata,
33
        ?SpacecraftInterface $triggerSpacecraft
34
    ): ?PirateBehaviourEnum {
35
36
        $leadWrapper = $fleet->getLeadWrapper();
37
38
        $hideSystems = $this->starSystemRepository->getPirateHides($leadWrapper);
39
        if ($hideSystems === []) {
40
            $this->logger->log('    no hide system in reach');
41
            return PirateBehaviourEnum::RAGE;
42
        }
43
44
        shuffle($hideSystems);
45
        $closestHideSystem = current($hideSystems);
46
47
        $this->pirateNavigation->navigateToTarget($fleet, $closestHideSystem);
48
49
        return null;
50
    }
51
}
52