Total Complexity | 10 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class Position implements NodeIdentifierInterface |
||
8 | { |
||
9 | private int $row; |
||
10 | private int $column; |
||
11 | |||
12 | 51 | public function __construct(int $row, int $column) |
|
13 | { |
||
14 | 51 | $this->validateNonNegativeInteger($row); |
|
15 | 50 | $this->validateNonNegativeInteger($column); |
|
16 | |||
17 | 49 | $this->row = $row; |
|
18 | 49 | $this->column = $column; |
|
19 | 49 | } |
|
20 | |||
21 | 40 | public function getRow(): int |
|
22 | { |
||
23 | 40 | return $this->row; |
|
24 | } |
||
25 | |||
26 | 36 | public function getColumn(): int |
|
27 | { |
||
28 | 36 | return $this->column; |
|
29 | } |
||
30 | |||
31 | 13 | public function isEqualTo(Position $other): bool |
|
32 | { |
||
33 | 13 | return $this->getRow() === $other->getRow() && $this->getColumn() === $other->getColumn(); |
|
34 | } |
||
35 | |||
36 | 24 | public function isAdjacentTo(Position $other): bool |
|
37 | { |
||
38 | 24 | return abs($this->getRow() - $other->getRow()) <= 1 && abs($this->getColumn() - $other->getColumn()) <= 1; |
|
39 | } |
||
40 | |||
41 | 8 | public function getUniqueNodeId(): string |
|
42 | { |
||
43 | 8 | return $this->row . 'x' . $this->column; |
|
44 | } |
||
45 | |||
46 | 51 | private function validateNonNegativeInteger(int $integer): void |
|
50 | } |
||
51 | 50 | } |
|
52 | } |
||
53 |