Passed
Push — master ( 152a70...0c8393 )
by Jose
03:00
created

Position::isAdjacentTo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace JMGQ\AStar\Example\Terrain;
4
5
class Position
6
{
7
    private int $row;
8
    private int $column;
9
10 49
    public function __construct(int $row, int $column)
11
    {
12 49
        $this->validateNonNegativeInteger($row);
13 48
        $this->validateNonNegativeInteger($column);
14
15 47
        $this->row = $row;
16 47
        $this->column = $column;
17 47
    }
18
19 40
    public function getRow(): int
20
    {
21 40
        return $this->row;
22
    }
23
24 36
    public function getColumn(): int
25
    {
26 36
        return $this->column;
27
    }
28
29 13
    public function isEqualTo(Position $other): bool
30
    {
31 13
        return $this->getRow() === $other->getRow() && $this->getColumn() === $other->getColumn();
32
    }
33
34 24
    public function isAdjacentTo(Position $other): bool
35
    {
36 24
        return abs($this->getRow() - $other->getRow()) <= 1 && abs($this->getColumn() - $other->getColumn()) <= 1;
37
    }
38
39 49
    private function validateNonNegativeInteger(int $integer): void
40
    {
41 49
        if ($integer < 0) {
42 2
            throw new \InvalidArgumentException("Invalid non negative integer: $integer");
43
        }
44 48
    }
45
}
46