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

EffectHandling::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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