Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 5 | class TranslationsSheetCoordinates |
||
|
|
|||
| 6 | { |
||
| 7 | protected $headerRowsCount = 1; |
||
| 8 | |||
| 9 | protected $dataRowsCount = 0; |
||
| 10 | |||
| 11 | protected $columnsCount = 0; |
||
| 12 | |||
| 13 | protected $localesCount = 1; |
||
| 14 | |||
| 15 | protected $sheetId; |
||
| 16 | |||
| 17 | protected $sheetTitle; |
||
| 18 | |||
| 19 | 8 | private function __construct() |
|
| 22 | |||
| 23 | 3 | public function setSheetId($sheetId) |
|
| 29 | |||
| 30 | 3 | public function setSheetTitle($sheetTitle) |
|
| 36 | |||
| 37 | 6 | public static function emptySheet($columnsCount, $localesCount, $headerRowsCount) |
|
| 48 | |||
| 49 | 2 | public static function sheetWithData($dataRowsCount, $columnsCount, $localesCount, $headerRowsCount) |
|
| 60 | |||
| 61 | public function headerShortRange() |
||
| 65 | |||
| 66 | 1 | View Code Duplication | public function headerRange() |
| 76 | |||
| 77 | 1 | View Code Duplication | public function fullKeyColumnRange() |
| 87 | |||
| 88 | 1 | public function metaColumnsRange() |
|
| 98 | |||
| 99 | 2 | public function dataShortRange($firstRow = 2, $noLastRow = false) |
|
| 107 | |||
| 108 | View Code Duplication | public function dataRange($endRow, $firstRow = 2) |
|
| 118 | |||
| 119 | 3 | public function translationsRange($firstColumn = 1, $rowCount = null) |
|
| 129 | |||
| 130 | 3 | public function getColumnsCount() |
|
| 134 | |||
| 135 | 5 | public function getRowsCount() |
|
| 139 | |||
| 140 | 3 | public function getLocalesCount() |
|
| 144 | |||
| 145 | 1 | public function namespaceColumnIndex() |
|
| 149 | |||
| 150 | 1 | public function groupColumnIndex() |
|
| 154 | |||
| 155 | 1 | public function keyColumnIndex() |
|
| 159 | |||
| 160 | 1 | public function sourceFileColumnIndex() |
|
| 164 | |||
| 165 | /** |
||
| 166 | * String from column index. |
||
| 167 | * |
||
| 168 | * @see https://github.com/PHPOffice/PhpSpreadsheet/blob/master/src/PhpSpreadsheet/Cell/Coordinate.php Source of implementation. |
||
| 169 | * |
||
| 170 | * @license https://raw.githubusercontent.com/PHPOffice/PhpSpreadsheet/master/LICENSE LGPL (GNU LESSER GENERAL PUBLIC LICENSE) |
||
| 171 | * |
||
| 172 | * @param int $columnIndex Column index (A = 1) |
||
| 173 | * |
||
| 174 | * @return string |
||
| 175 | */ |
||
| 176 | 2 | public static function stringFromColumnIndex($columnIndex) |
|
| 191 | } |
||
| 192 |