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

Movement::fromString()   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 1
crap 1
1
<?php
2
3
namespace Kata\Rover\Domain\Model;
4
5
class Movement
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 $movement;
8
9 2
    private function __construct(string $movement)
10
    {
11 2
        $this->movement = $movement;
12 2
    }
13
14 2
    public static function fromString($movement): Movement
15
    {
16 2
        return new self($movement);
17
    }
18
19 2
    public function isForward(): bool
20
    {
21 2
        return 'f' === $this->movement;
22
    }
23
24
    public function isBackward(): bool
25
    {
26
        return 'b' === $this->movement;
27
    }
28
29 2
    public function isLeft(): bool
30
    {
31 2
        return 'l' === $this->movement;
32
    }
33
34 2
    public function isRight(): bool
35
    {
36 2
        return 'r' === $this->movement;
37
    }
38
39 2
    public function isTurn(): bool
40
    {
41 2
        return $this->isLeft() || $this->isRight();
42
    }
43
}