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

Direction::turnLeft()   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 Direction
6
{
7
    public const NORTH = 'n';
8
    public const SOUTH = 's';
9
    public const EAST = 'e';
10
    public const WEST = 'w';
11
12
    public const DIRECTIONS = [
13
        self::NORTH => [
14
            'right' => self::EAST,
15
            'left' => self::WEST
16
        ],
17
        self::EAST => [
18
            'right' => self::SOUTH,
19
            'left' => self::NORTH
20
        ],
21
        self::SOUTH => [
22
            'right' => self::WEST,
23
            'left' => self::EAST
24
        ],
25
        self::WEST => [
26
            'right' => self::NORTH,
27
            'left' => self::SOUTH
28
        ]
29
    ];
30
31
    private $direction;
32
33 14
    private function __construct(string $direction)
34
    {
35 14
        $this->direction = $direction;
36 14
    }
37
38 14
    public static function north(): Direction
39
    {
40 14
        return new self(Direction::NORTH);
41
    }
42
43 3
    public static function south(): Direction
44
    {
45 3
        return new self(Direction::SOUTH);
46
    }
47
48 4
    public static function east(): Direction
49
    {
50 4
        return new self(Direction::EAST);
51
    }
52
53 4
    public static function west(): Direction
54
    {
55 4
        return new self(Direction::WEST);
56
    }
57
58 5
    public function turnRight(): Direction
59
    {
60 5
        return new Direction(self::DIRECTIONS[$this->direction]['right']);
61
    }
62
63 5
    public function turnLeft(): Direction
64
    {
65 5
        return new Direction(self::DIRECTIONS[$this->direction]['left']);
66
    }
67
68 1
    public function direction(): string
69
    {
70 1
        return $this->direction;
71
    }
72
}
73