PickAction   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 17 3
A getAlias() 0 4 1
A getArguments() 0 4 1
1
<?php
2
declare(strict_types=1);
3
namespace Thunder\Logeek\Action;
4
5
use Thunder\Logeek\ActionInterface;
6
use Thunder\Logeek\Board;
7
8
final class PickAction implements ActionInterface
9
{
10
    private static $moveMap = [
11
        'left' => [0, -1],
12
        'right' => [0, 1],
13
        'up' => [-1, 0],
14
        'down' => [1, 0],
15
    ];
16
17
    public function execute(Board $board, string $alias, array $operation)
18
    {
19
        $direction = $board->getActorDirection($alias);
20
        list($x, $y) = $board->getActorPosition($alias);
21
        $newX = $x + static::$moveMap[$direction][0];
0 ignored issues
show
Comprehensibility introduced by
Since Thunder\Logeek\Action\PickAction is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
22
        $newY = $y + static::$moveMap[$direction][1];
0 ignored issues
show
Comprehensibility introduced by
Since Thunder\Logeek\Action\PickAction is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
23
24
        if('up' === $operation['direction']) {
25
            $board->debug('Pick[up]');
26
            $board->setField($newX, $newY, 'ground');
27
            $board->setActorPick($alias, 'brick');
28
        } elseif('down' === $operation['direction']) {
29
            $board->debug('Pick[down]');
30
            $board->setField($newX, $newY, 'brick');
31
            $board->setActorPick($alias, null);
32
        }
33
    }
34
35
    public function getAlias(): string
36
    {
37
        return 'pick';
38
    }
39
40
    public function getArguments(): array
41
    {
42
        return ['direction'];
43
    }
44
}
45