Conditions | 3 |
Paths | 1 |
Total Lines | 172 |
Code Lines | 115 |
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 |
||
239 | protected function initializeMappings() |
||
240 | { |
||
241 | $this->mappings['autoFilter'] = function ($value) { |
||
242 | $this->object->setAutoFilter($value); |
||
243 | }; |
||
244 | $this->mappings['columnDimension']['__multi'] = function ($column = 'default'): ColumnDimension { |
||
245 | return $column === 'default' ? |
||
246 | $this->object->getDefaultColumnDimension() : |
||
247 | $this->object->getColumnDimension($column); |
||
248 | }; |
||
249 | $this->mappings['columnDimension']['autoSize'] = function ($value, ColumnDimension $object) { |
||
250 | $object->setAutoSize($value); |
||
251 | }; |
||
252 | $this->mappings['columnDimension']['collapsed'] = function ($value, ColumnDimension $object) { |
||
253 | $object->setCollapsed($value); |
||
254 | }; |
||
255 | $this->mappings['columnDimension']['columnIndex'] = function ($value, ColumnDimension $object) { |
||
256 | $object->setColumnIndex($value); |
||
257 | }; |
||
258 | $this->mappings['columnDimension']['outlineLevel'] = function ($value, ColumnDimension $object) { |
||
259 | $object->setOutlineLevel($value); |
||
260 | }; |
||
261 | $this->mappings['columnDimension']['visible'] = function ($value, ColumnDimension $object) { |
||
262 | $object->setVisible($value); |
||
263 | }; |
||
264 | $this->mappings['columnDimension']['width'] = function ($value, ColumnDimension $object) { |
||
265 | $object->setWidth($value); |
||
266 | }; |
||
267 | $this->mappings['columnDimension']['xfIndex'] = function ($value, ColumnDimension $object) { |
||
268 | $object->setXfIndex($value); |
||
269 | }; |
||
270 | $this->mappings['pageMargins']['top'] = function ($value) { |
||
271 | $this->object->getPageMargins()->setTop($value); |
||
272 | }; |
||
273 | $this->mappings['pageMargins']['bottom'] = function ($value) { |
||
274 | $this->object->getPageMargins()->setBottom($value); |
||
275 | }; |
||
276 | $this->mappings['pageMargins']['left'] = function ($value) { |
||
277 | $this->object->getPageMargins()->setLeft($value); |
||
278 | }; |
||
279 | $this->mappings['pageMargins']['right'] = function ($value) { |
||
280 | $this->object->getPageMargins()->setRight($value); |
||
281 | }; |
||
282 | $this->mappings['pageMargins']['header'] = function ($value) { |
||
283 | $this->object->getPageMargins()->setHeader($value); |
||
284 | }; |
||
285 | $this->mappings['pageMargins']['footer'] = function ($value) { |
||
286 | $this->object->getPageMargins()->setFooter($value); |
||
287 | }; |
||
288 | $this->mappings['pageSetup']['fitToHeight'] = function ($value) { |
||
289 | $this->object->getPageSetup()->setFitToHeight($value); |
||
290 | }; |
||
291 | $this->mappings['pageSetup']['fitToPage'] = function ($value) { |
||
292 | $this->object->getPageSetup()->setFitToPage($value); |
||
293 | }; |
||
294 | $this->mappings['pageSetup']['fitToWidth'] = function ($value) { |
||
295 | $this->object->getPageSetup()->setFitToWidth($value); |
||
296 | }; |
||
297 | $this->mappings['pageSetup']['horizontalCentered'] = function ($value) { |
||
298 | $this->object->getPageSetup()->setHorizontalCentered($value); |
||
299 | }; |
||
300 | $this->mappings['pageSetup']['orientation'] = function ($value) { |
||
301 | $this->object->getPageSetup()->setOrientation($value); |
||
302 | }; |
||
303 | $this->mappings['pageSetup']['paperSize'] = function ($value) { |
||
304 | $this->object->getPageSetup()->setPaperSize($value); |
||
305 | }; |
||
306 | $this->mappings['pageSetup']['printArea'] = function ($value) { |
||
307 | $this->object->getPageSetup()->setPrintArea($value); |
||
308 | }; |
||
309 | $this->mappings['pageSetup']['scale'] = function ($value) { |
||
310 | $this->object->getPageSetup()->setScale($value); |
||
311 | }; |
||
312 | $this->mappings['pageSetup']['verticalCentered'] = function ($value) { |
||
313 | $this->object->getPageSetup()->setVerticalCentered($value); |
||
314 | }; |
||
315 | $this->mappings['printGridlines'] = function ($value) { |
||
316 | $this->object->setPrintGridlines($value); |
||
317 | }; |
||
318 | $this->mappings['protection']['autoFilter'] = function ($value) { |
||
319 | $this->object->getProtection()->setAutoFilter($value); |
||
320 | }; |
||
321 | $this->mappings['protection']['deleteColumns'] = function ($value) { |
||
322 | $this->object->getProtection()->setDeleteColumns($value); |
||
323 | }; |
||
324 | $this->mappings['protection']['deleteRows'] = function ($value) { |
||
325 | $this->object->getProtection()->setDeleteRows($value); |
||
326 | }; |
||
327 | $this->mappings['protection']['formatCells'] = function ($value) { |
||
328 | $this->object->getProtection()->setFormatCells($value); |
||
329 | }; |
||
330 | $this->mappings['protection']['formatColumns'] = function ($value) { |
||
331 | $this->object->getProtection()->setFormatColumns($value); |
||
332 | }; |
||
333 | $this->mappings['protection']['formatRows'] = function ($value) { |
||
334 | $this->object->getProtection()->setFormatRows($value); |
||
335 | }; |
||
336 | $this->mappings['protection']['insertColumns'] = function ($value) { |
||
337 | $this->object->getProtection()->setInsertColumns($value); |
||
338 | }; |
||
339 | $this->mappings['protection']['insertHyperlinks'] = function ($value) { |
||
340 | $this->object->getProtection()->setInsertHyperlinks($value); |
||
341 | }; |
||
342 | $this->mappings['protection']['insertRows'] = function ($value) { |
||
343 | $this->object->getProtection()->setInsertRows($value); |
||
344 | }; |
||
345 | $this->mappings['protection']['objects'] = function ($value) { |
||
346 | $this->object->getProtection()->setObjects($value); |
||
347 | }; |
||
348 | $this->mappings['protection']['password'] = function ($value) { |
||
349 | $this->object->getProtection()->setPassword($value); |
||
350 | }; |
||
351 | $this->mappings['protection']['pivotTables'] = function ($value) { |
||
352 | $this->object->getProtection()->setPivotTables($value); |
||
353 | }; |
||
354 | $this->mappings['protection']['scenarios'] = function ($value) { |
||
355 | $this->object->getProtection()->setScenarios($value); |
||
356 | }; |
||
357 | $this->mappings['protection']['selectLockedCells'] = function ($value) { |
||
358 | $this->object->getProtection()->setSelectLockedCells($value); |
||
359 | }; |
||
360 | $this->mappings['protection']['selectUnlockedCells'] = function ($value) { |
||
361 | $this->object->getProtection()->setSelectUnlockedCells($value); |
||
362 | }; |
||
363 | $this->mappings['protection']['sheet'] = function ($value) { |
||
364 | $this->object->getProtection()->setSheet($value); |
||
365 | }; |
||
366 | $this->mappings['protection']['sort'] = function ($value) { |
||
367 | $this->object->getProtection()->setSort($value); |
||
368 | }; |
||
369 | $this->mappings['rightToLeft'] = function ($value) { |
||
370 | $this->object->setRightToLeft($value); |
||
371 | }; |
||
372 | $this->mappings['rowDimension']['__multi'] = function ($column = 'default'): RowDimension { |
||
373 | return $column === 'default' ? |
||
374 | $this->object->getDefaultRowDimension() : |
||
375 | $this->object->getRowDimension($column); |
||
376 | }; |
||
377 | $this->mappings['rowDimension']['collapsed'] = function ($value, RowDimension $object) { |
||
378 | $object->setCollapsed($value); |
||
379 | }; |
||
380 | $this->mappings['rowDimension']['outlineLevel'] = function ($value, RowDimension $object) { |
||
381 | $object->setOutlineLevel($value); |
||
382 | }; |
||
383 | $this->mappings['rowDimension']['rowHeight'] = function ($value, RowDimension $object) { |
||
384 | $object->setRowHeight($value); |
||
385 | }; |
||
386 | $this->mappings['rowDimension']['rowIndex'] = function ($value, RowDimension $object) { |
||
387 | $object->setRowIndex($value); |
||
388 | }; |
||
389 | $this->mappings['rowDimension']['visible'] = function ($value, RowDimension $object) { |
||
390 | $object->setVisible($value); |
||
391 | }; |
||
392 | $this->mappings['rowDimension']['xfIndex'] = function ($value, RowDimension $object) { |
||
393 | $object->setXfIndex($value); |
||
394 | }; |
||
395 | $this->mappings['rowDimension']['zeroHeight'] = function ($value, RowDimension $object) { |
||
396 | $object->setZeroHeight($value); |
||
397 | }; |
||
398 | $this->mappings['sheetState'] = function ($value) { |
||
399 | $this->object->setSheetState($value); |
||
400 | }; |
||
401 | $this->mappings['showGridlines'] = function ($value) { |
||
402 | $this->object->setShowGridlines($value); |
||
403 | }; |
||
404 | $this->mappings['tabColor'] = function ($value) { |
||
405 | $this->object->getTabColor()->setRGB($value); |
||
406 | }; |
||
407 | $this->mappings['zoomScale'] = function ($value) { |
||
408 | $this->object->getSheetView()->setZoomScale($value); |
||
409 | }; |
||
410 | } |
||
411 | } |
||
412 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.