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

Orientation   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 72.41%

Importance

Changes 0
Metric Value
wmc 26
lcom 1
cbo 1
dl 0
loc 72
ccs 21
cts 29
cp 0.7241
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A NORTH() 0 4 1
A SOUTH() 0 4 1
A EAST() 0 4 1
A WEST() 0 4 1
A isNorth() 0 4 1
A isSouth() 0 4 1
A isEast() 0 4 1
A isWest() 0 4 1
C turn() 0 22 17
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
}