| Conditions | 19 |
| Paths | 2 |
| Total Lines | 75 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 165 | protected function init() |
||
| 166 | { |
||
| 167 | if (empty($this->data['databaseRow']['config'])) { |
||
| 168 | $rows = [[['colspan' => 1, 'rowspan' => 1, 'spanned' => 0, 'name' => '0x0']]]; |
||
| 169 | $colCount = 1; |
||
| 170 | $rowCount = 1; |
||
| 171 | } else { |
||
| 172 | // load TS parser |
||
| 173 | $parser = GeneralUtility::makeInstance(TypoScriptParser::class); |
||
| 174 | $parser->parse($this->data['databaseRow']['config']); |
||
| 175 | $data = $parser->setup['backend_layout.']; |
||
| 176 | $rows = []; |
||
| 177 | $colCount = $data['colCount']; |
||
| 178 | $rowCount = $data['rowCount']; |
||
| 179 | $dataRows = $data['rows.']; |
||
| 180 | $spannedMatrix = []; |
||
| 181 | for ($i = 1; $i <= $rowCount; $i++) { |
||
| 182 | $cells = []; |
||
| 183 | $row = array_shift($dataRows); |
||
| 184 | $columns = $row['columns.']; |
||
| 185 | for ($j = 1; $j <= $colCount; $j++) { |
||
| 186 | $cellData = []; |
||
| 187 | if (!$spannedMatrix[$i][$j]) { |
||
| 188 | if (is_array($columns) && !empty($columns)) { |
||
| 189 | $column = array_shift($columns); |
||
| 190 | if (isset($column['colspan'])) { |
||
| 191 | $cellData['colspan'] = (int)$column['colspan']; |
||
| 192 | $columnColSpan = (int)$column['colspan']; |
||
| 193 | if (isset($column['rowspan'])) { |
||
| 194 | $columnRowSpan = (int)$column['rowspan']; |
||
| 195 | for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) { |
||
| 196 | for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) { |
||
| 197 | $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | } else { |
||
| 201 | for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) { |
||
| 202 | $spannedMatrix[$i][$j + $spanColumn] = 1; |
||
| 203 | } |
||
| 204 | } |
||
| 205 | } else { |
||
| 206 | $cellData['colspan'] = 1; |
||
| 207 | if (isset($column['rowspan'])) { |
||
| 208 | $columnRowSpan = (int)$column['rowspan']; |
||
| 209 | for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) { |
||
| 210 | $spannedMatrix[$i + $spanRow][$j] = 1; |
||
| 211 | } |
||
| 212 | } |
||
| 213 | } |
||
| 214 | if (isset($column['rowspan'])) { |
||
| 215 | $cellData['rowspan'] = (int)$column['rowspan']; |
||
| 216 | } else { |
||
| 217 | $cellData['rowspan'] = 1; |
||
| 218 | } |
||
| 219 | if (isset($column['name'])) { |
||
| 220 | $cellData['name'] = $column['name']; |
||
| 221 | } |
||
| 222 | if (isset($column['colPos'])) { |
||
| 223 | $cellData['column'] = (int)$column['colPos']; |
||
| 224 | } |
||
| 225 | } |
||
| 226 | } else { |
||
| 227 | $cellData = ['colspan' => 1, 'rowspan' => 1, 'spanned' => 1]; |
||
| 228 | } |
||
| 229 | $cells[] = $cellData; |
||
| 230 | } |
||
| 231 | $rows[] = $cells; |
||
| 232 | if (!empty($spannedMatrix[$i]) && is_array($spannedMatrix[$i])) { |
||
| 233 | ksort($spannedMatrix[$i]); |
||
| 234 | } |
||
| 235 | } |
||
| 236 | } |
||
| 237 | $this->rows = $rows; |
||
| 238 | $this->colCount = (int)$colCount; |
||
| 239 | $this->rowCount = (int)$rowCount; |
||
| 240 | } |
||
| 242 |