| Total Complexity | 6 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class Coordinate |
||
| 8 | { |
||
| 9 | /** @var int */ |
||
| 10 | protected $row; |
||
| 11 | |||
| 12 | /** @var int */ |
||
| 13 | protected $column; |
||
| 14 | |||
| 15 | /** @var int */ |
||
| 16 | protected $columns; |
||
| 17 | |||
| 18 | /** @var int */ |
||
| 19 | protected $position; |
||
| 20 | |||
| 21 | 15 | public function __construct(int $row, int $column, int $columns) |
|
| 22 | { |
||
| 23 | 15 | $this->row = $row; |
|
| 24 | 15 | $this->column = $column; |
|
| 25 | 15 | $this->columns = $columns; |
|
| 26 | 15 | $this->position = $this->calculatePosition(); |
|
| 27 | 15 | } |
|
| 28 | |||
| 29 | 3 | public function __toString(): string |
|
| 30 | { |
||
| 31 | 3 | return sprintf("%d, %d", $this->row, $this->column); |
|
| 32 | } |
||
| 33 | |||
| 34 | 3 | public function row(): int |
|
| 35 | { |
||
| 36 | 3 | return $this->row; |
|
| 37 | } |
||
| 38 | |||
| 39 | 3 | public function column(): int |
|
| 40 | { |
||
| 41 | 3 | return $this->column; |
|
| 42 | } |
||
| 43 | |||
| 44 | 15 | protected function calculatePosition(): int |
|
| 45 | { |
||
| 46 | 15 | return ($this->row * $this->columns) + $this->column; |
|
| 47 | } |
||
| 48 | |||
| 49 | 6 | public function position(): int |
|
| 52 | } |
||
| 53 | } |
||
| 54 |