Passed
Push — master ( 128fe0...fa7a2a )
by Nico
10:40
created

EffectHandling   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 15.38%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 34
ccs 2
cts 13
cp 0.1538
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHandler() 0 9 2
A handleSpacecraftTick() 0 5 2
A handleIncomingSpacecraft() 0 5 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Map\Effects;
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 RuntimeException;
9
use Stu\Component\Map\Effects\Type\EffectHandlerInterface;
10
use Stu\Lib\Information\InformationInterface;
11
use Stu\Lib\Map\FieldTypeEffectEnum;
12
use Stu\Module\Spacecraft\Lib\Message\MessageCollectionInterface;
13
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
14
15
final class EffectHandling implements EffectHandlingInterface
16
{
17
    /**
18
     * @param array<string, EffectHandlerInterface> $handlerList
19
     */
20 1
    public function __construct(
21
        private array $handlerList
22 1
    ) {}
23
24
    #[Override]
25
    public function handleSpacecraftTick(SpacecraftWrapperInterface $wrapper, InformationInterface $information): void
26
    {
27
        foreach ($wrapper->get()->getLocation()->getFieldType()->getEffects() as $effect) {
28
            $this->getHandler($effect)->handleSpacecraftTick($wrapper, $information);
29
        }
30
    }
31
32
    #[Override]
33
    public function handleIncomingSpacecraft(SpacecraftWrapperInterface $wrapper, MessageCollectionInterface $messages): void
34
    {
35
        foreach ($wrapper->get()->getLocation()->getFieldType()->getEffects() as $effect) {
36
            $this->getHandler($effect)->handleIncomingSpacecraft($wrapper, $messages);
37
        }
38
    }
39
40
    private function getHandler(FieldTypeEffectEnum $effect): EffectHandlerInterface
41
    {
42
        if (!array_key_exists($effect->value, $this->handlerList)) {
43
            throw new RuntimeException(sprintf('no handler defined for type: %d', $effect->value));
44
        }
45
46
        $handler = $this->handlerList[$effect->value];
47
48
        return $handler;
49
    }
50
}
51