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

Position   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 13
c 1
b 0
f 0
dl 0
loc 38
ccs 17
cts 17
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A validateNonNegativeInteger() 0 4 2
A getRow() 0 3 1
A isEqualTo() 0 3 2
A __construct() 0 7 1
A isAdjacentTo() 0 3 2
A getColumn() 0 3 1
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