Completed
Push — rover-kata ( cc14c5...e33e35 )
by Marcos
02:36
created

Rover::coordinates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Kata\Rover;
4
5
final class Rover
6
{
7
    private $map;
8
    private $coordinates;
9
    private $direction;
10
11 5
    public function __construct(Map $a_map, Coordinates $a_starting_point, Direction $a_direction)
12
    {
13 5
        $this->map = $a_map;
14 5
        $this->coordinates = $a_starting_point;
15 5
        $this->direction = $a_direction;
16 5
    }
17
18
    public function map(): Map
19
    {
20
        return $this->map;
21
    }
22
23 5
    public function coordinates(): Coordinates
24
    {
25 5
        return $this->coordinates;
26
    }
27
28 2
    public function direction(): Direction
29
    {
30 2
        return $this->direction;
31
    }
32
33 4
    public function commands(array $commands): void
34
    {
35 4
        foreach ($commands as $command) {
36 4
            $this->process($command);
37
        }
38 4
    }
39
40 4
    private function process(string $command): void
41
    {
42 4
        if ('f' === $command) {
43 1
            $this->coordinates = new Coordinates(
44 1
                $this->coordinates->coordinateX(),
45 1
                $this->coordinates->coordinateY() + 1
46
            );
47
        }
48 4
        if ('b' === $command) {
49 1
            $this->coordinates = new Coordinates(
50 1
                $this->coordinates->coordinateX(),
51 1
                $this->coordinates->coordinateY() - 1
52
            );
53
        }
54 4
        if ('r' === $command) {
55 1
            $this->direction = $this->direction->turnRight();
56
        }
57 4
        if ('l' === $command) {
58 1
            $this->direction = $this->direction->turnLeft();
59
        }
60 4
    }
61
}
62