| Conditions | 5 |
| Paths | 5 |
| Total Lines | 19 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public static function checkStraightLine(array $coordinates): bool |
||
| 10 | { |
||
| 11 | if (empty($coordinates)) { |
||
| 12 | return false; |
||
| 13 | } |
||
| 14 | if (($n = count($coordinates)) === 2) { |
||
| 15 | return true; |
||
| 16 | } |
||
| 17 | [$x1, $y1] = [$coordinates[0][0], $coordinates[0][1]]; |
||
| 18 | [$x2, $y2] = [$coordinates[1][0], $coordinates[1][1]]; |
||
| 19 | for ($i = 2; $i < $n; $i++) { |
||
| 20 | [$x, $y] = [$coordinates[$i][0], $coordinates[$i][1]]; |
||
| 21 | // (y - y1) / (y2 - y1) = (x - x1) / (x2 - x1) |
||
| 22 | if (($y - $y1) * ($x2 - $x1) !== ($y2 - $y1) * ($x - $x1)) { |
||
| 23 | return false; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | return true; |
||
| 28 | } |
||
| 30 |