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 namespace VojtaSvoboda\Reservations\Controllers; |
||
| 12 | class Reservations extends Controller |
||
| 13 | { |
||
| 14 | public $implement = [ |
||
| 15 | 'Backend\Behaviors\ListController', |
||
| 16 | 'Backend\Behaviors\FormController', |
||
| 17 | 'Backend\Behaviors\ImportExportController', |
||
| 18 | ]; |
||
| 19 | |||
| 20 | public $listConfig = 'config_list.yaml'; |
||
| 21 | public $formConfig = 'config_form.yaml'; |
||
| 22 | public $importExportConfig = 'config_import_export.yaml'; |
||
| 23 | |||
| 24 | private $stateColors; |
||
| 25 | private $stateNames; |
||
| 26 | |||
| 27 | public $requiredPermissions = [ |
||
| 28 | 'vojtasvoboda.reservations.reservations', |
||
| 29 | ]; |
||
| 30 | |||
| 31 | public function __construct() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Extend controller listing. |
||
| 41 | */ |
||
| 42 | public function index() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Override displaying reservation listing. |
||
| 50 | * |
||
| 51 | * @param Reservation $record |
||
| 52 | * @param string $columnName |
||
| 53 | * |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public function listOverrideColumnValue($record, $columnName) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Bulk change state and bulk delete. |
||
| 74 | * |
||
| 75 | * @return mixed |
||
| 76 | */ |
||
| 77 | public function index_onBulkAction() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Return if User is returning. |
||
| 95 | * |
||
| 96 | * @param string $email Users email. |
||
| 97 | * |
||
| 98 | * @return bool |
||
| 99 | */ |
||
| 100 | private function isReturning($email) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Get facade providing all plugin logic. |
||
| 107 | * |
||
| 108 | * @return ReservationsFacade |
||
| 109 | */ |
||
| 110 | private function getFacade() |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Get color by state ident. |
||
| 117 | * |
||
| 118 | * @param string $ident |
||
| 119 | * |
||
| 120 | * @return string|null |
||
| 121 | */ |
||
| 122 | View Code Duplication | private function getStateColor($ident) |
|
| 130 | |||
| 131 | /** |
||
| 132 | * Get name by state ident. |
||
| 133 | * |
||
| 134 | * @param string $ident |
||
| 135 | * |
||
| 136 | * @return string|null |
||
| 137 | */ |
||
| 138 | View Code Duplication | private function getStateName($ident) |
|
| 146 | } |
||
| 147 |