Completed
Push — Rover/albertg ( 3c48fc )
by Albert
01:56
created

Orientation::SOUTH()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Kata\Rover\Domain\Model;
4
5
class Orientation
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
6
{
7
    private $orientation;
8
9 1
    private function __construct(string $orientation)
10
    {
11 1
        $this->orientation = $orientation;
12 1
    }
13
14 1
    public static function NORTH(): Orientation
15
    {
16 1
        return new self('N');
17
    }
18
19
    public static function SOUTH(): Orientation
20
    {
21
        return new self('S');
22
    }
23
24 1
    public static function EAST(): Orientation
25
    {
26 1
        return new self('E');
27
    }
28
29
    public static function WEST(): Orientation
30
    {
31
        return new self('W');
32
    }
33
34 2
    public function isNorth(): bool
35
    {
36 2
        return $this->orientation === 'N';
37
    }
38
39 2
    public function isSouth(): bool
40
    {
41 2
        return $this->orientation === 'S';
42
    }
43
44 2
    public function isEast(): bool
45
    {
46 2
        return $this->orientation === 'E';
47
    }
48
49 1
    public function isWest(): bool
50
    {
51 1
        return $this->orientation === 'W';
52
    }
53
54 1
    public function turn(Movement $movement): Orientation
55
    {
56 1
        if (($movement->isLeft() && $this->isEast()) || ($movement->isRight() && $this->isWest()))
57
        {
58 1
            return self::NORTH();
59
        }
60
61 1
        if (($movement->isLeft() && $this->isWest()) || ($movement->isRight() && $this->isEast()))
62
        {
63
            return self::SOUTH();
64
        }
65
66 1
        if (($movement->isLeft() && $this->isSouth()) || ($movement->isRight() && $this->isNorth()))
67
        {
68 1
            return self::EAST();
69
        }
70
71
        if (($movement->isLeft() && $this->isNorth()) || ($movement->isRight() && $this->isSouth()))
72
        {
73
            return self::WEST();
74
        }
75
    }
76
}