| Total Complexity | 9 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 |
|
| 43 | } |
||
| 44 | 48 | } |
|
| 45 | } |
||
| 46 |