public function isValid(Matrix $matrix) { $rowsSize = array_map(function ($row) { return count($row); }, $matrix->toArray()); return count($rowsSize) > 0 && count(array_keys($rowsSize, $rowsSize[0])) == count($rowsSize); }
protected function traverseRow(Matrix $matrix, $rotatedMatrix, $rowIndex) { for ($columnIndex = 0, $width = $matrix->getWidth(); $columnIndex < $width; $columnIndex++) { if (!isset($rotatedMatrix[$rowIndex]) || !isset($rotatedMatrix[$columnIndex])) { $rotatedMatrix[$columnIndex] = []; } $rotatedMatrix[$columnIndex] = $this->addValueToRow($rotatedMatrix[$columnIndex], $this->getMatrixValue($matrix, $rowIndex, $columnIndex)); } return $rotatedMatrix; }
protected function getMatrixValue(Matrix $matrix, $rowIndex, $columnIndex) { return $matrix->getValue($rowIndex, $columnIndex); }