MoveAction   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 7 2
A getMoveLength() 0 12 2
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 MoveAction implements ActionInterface
9
{
10
    public function execute(Board $board, string $alias, array $operation)
11
    {
12
        $length = $this->getMoveLength($board, $operation);
13
        for($i = 0; $i < $length; $i++) {
14
            $board->moveActor($alias);
15
        }
16
    }
17
18
    private function getMoveLength(Board $board, array $operation)
19
    {
20
        if(is_numeric($operation['distance'])) {
21
            $length = $operation['distance'];
22
            $board->debug('Move Length[%s]', $length);
23
            return $length;
24
        }
25
26
        $length = $board->getVariable($operation['distance']);
27
        $board->debug('Move Variable[%s] Length[%s]', $operation['distance'], $length);
28
        return $length;
29
    }
30
31
    public function getAlias(): string
32
    {
33
        return 'move';
34
    }
35
36
    public function getArguments(): array
37
    {
38
        return ['distance'];
39
    }
40
}
41