for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace JMGQ\AStar\Example\Terrain;
class Position
{
private int $row;
private int $column;
public function __construct(int $row, int $column)
$this->validateNonNegativeInteger($row);
$this->validateNonNegativeInteger($column);
$this->row = $row;
$this->column = $column;
}
public function getRow(): int
return $this->row;
public function getColumn(): int
return $this->column;
public function isEqualTo(Position $other): bool
return $this->getRow() === $other->getRow() && $this->getColumn() === $other->getColumn();
public function isAdjacentTo(Position $other): bool
return abs($this->getRow() - $other->getRow()) <= 1 && abs($this->getColumn() - $other->getColumn()) <= 1;
private function validateNonNegativeInteger(int $integer): void
if ($integer < 0) {
throw new \InvalidArgumentException("Invalid non negative integer: $integer");