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() |
||
67 | |||
68 | 1 | View Code Duplication | public function headerRange() |
69 | { |
||
70 | return [ |
||
71 | 1 | 'sheetId' => $this->sheetId, |
|
72 | 1 | 'startRowIndex' => 0, |
|
73 | 1 | 'endRowIndex' => 1, |
|
74 | 1 | 'startColumnIndex' => 0, |
|
75 | 1 | 'endColumnIndex' => $this->getColumnsCount(), |
|
76 | 1 | ]; |
|
77 | } |
||
78 | |||
79 | 1 | View Code Duplication | public function fullKeyColumnRange() |
80 | { |
||
81 | return [ |
||
82 | 1 | 'sheetId' => $this->sheetId, |
|
83 | 1 | 'startRowIndex' => 1, |
|
84 | 1 | 'endRowIndex' => $this->getRowsCount(), |
|
85 | 1 | 'startColumnIndex' => 0, |
|
86 | 1 | 'endColumnIndex' => 1, |
|
87 | 1 | ]; |
|
88 | } |
||
89 | |||
90 | 1 | public function metaColumnsRange() |
|
100 | |||
101 | 2 | public function dataShortRange($firstRow = 2, $noLastRow = false) |
|
110 | |||
111 | View Code Duplication | public function dataRange($endRow, $firstRow = 2) |
|
112 | { |
||
113 | return [ |
||
114 | 'sheetId' => $this->sheetId, |
||
115 | 'startRowIndex' => $firstRow, |
||
116 | 'endRowIndex' => $endRow, |
||
117 | 'startColumnIndex' => 0, |
||
118 | 'endColumnIndex' => $this->getColumnsCount(), |
||
119 | ]; |
||
120 | } |
||
121 | |||
122 | 3 | public function translationsRange($firstColumn = 1, $rowCount = null) |
|
132 | |||
133 | 3 | public function getColumnsCount() |
|
137 | |||
138 | 5 | public function getRowsCount() |
|
142 | |||
143 | 3 | public function getLocalesCount() |
|
147 | |||
148 | 1 | public function namespaceColumnIndex() |
|
152 | |||
153 | 1 | public function groupColumnIndex() |
|
157 | |||
158 | 1 | public function keyColumnIndex() |
|
162 | |||
163 | 1 | public function sourceFileColumnIndex() |
|
167 | } |
||
168 |