| Total Complexity | 9 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Coverage | 52.63% |
| Changes | 0 | ||
| 1 | <?php |
||
| 13 | final class Coordinate implements JsonSerializable, Stringable |
||
| 14 | { |
||
| 15 | private int $coordinateX; |
||
| 16 | private int $coordinateY; |
||
| 17 | |||
| 18 | public function __construct(int $coordinateX, int $coordinateY) |
||
| 19 | { |
||
| 20 | $this->coordinateX = $coordinateX; |
||
| 21 | $this->coordinateY = $coordinateY; |
||
| 22 | } |
||
| 23 | |||
| 24 | 2 | public function inFrame(): bool |
|
| 25 | { |
||
| 26 | 2 | return 0 < $this->coordinateX && 0 < $this->coordinateY; |
|
| 27 | } |
||
| 28 | |||
| 29 | 1 | public function left(): self |
|
| 30 | { |
||
| 31 | 1 | return new self($this->coordinateX - 1, $this->coordinateY); |
|
| 32 | } |
||
| 33 | |||
| 34 | 1 | public function right(): self |
|
| 35 | { |
||
| 36 | 1 | return new self($this->coordinateX + 1, $this->coordinateY); |
|
| 37 | } |
||
| 38 | |||
| 39 | 1 | public function top(): self |
|
| 40 | { |
||
| 41 | 1 | return new self($this->coordinateX, $this->coordinateY + 1); |
|
| 42 | } |
||
| 43 | |||
| 44 | 1 | public function down(): self |
|
| 45 | { |
||
| 46 | 1 | return new self($this->coordinateX, $this->coordinateY - 1); |
|
| 47 | } |
||
| 48 | |||
| 49 | public function jsonSerialize(): array |
||
| 50 | { |
||
| 51 | return [ |
||
| 52 | 'x' => $this->coordinateX, |
||
| 53 | 'y' => $this->coordinateY, |
||
| 54 | ]; |
||
| 55 | } |
||
| 56 | |||
| 57 | public function __toString(): string |
||
| 60 | } |
||
| 61 | } |
||
| 62 |