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 |
||
| 33 | class SettingsController extends Controller { |
||
| 34 | |||
| 35 | private $userId; |
||
| 36 | private $appConfig; |
||
| 37 | private $navigationManager; |
||
| 38 | private $util; |
||
| 39 | |||
| 40 | 5 | public function __construct($appName, IRequest $request, ConfigService $appConfig, INavigationManager $urlGenerator, Util $util, $userId) { |
|
| 47 | |||
| 48 | /** |
||
| 49 | * Admin: render admin page |
||
| 50 | * FIXME: Move to dedicated class |
||
| 51 | * |
||
| 52 | * @return TemplateResponse |
||
| 53 | */ |
||
| 54 | 1 | View Code Duplication | public function adminIndex() { |
| 67 | 1 | ||
| 68 | View Code Duplication | public function personalIndex() { |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Admin: save default order |
||
| 84 | * |
||
| 85 | * @param $order |
||
| 86 | 1 | * @return array response |
|
| 87 | 1 | */ |
|
| 88 | 1 | public function saveDefaultOrder($order) { |
|
| 94 | |||
| 95 | /** |
||
| 96 | * Return order for current user |
||
| 97 | * |
||
| 98 | * @NoAdminRequired |
||
| 99 | 1 | * @return array response |
|
| 100 | 1 | */ |
|
| 101 | 1 | public function getOrder() { |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Save order for current user |
||
| 109 | * |
||
| 110 | * @NoAdminRequired |
||
| 111 | 1 | * @param $order string |
|
| 112 | 1 | * @return array response |
|
| 113 | */ |
||
| 114 | 1 | View Code Duplication | public function savePersonal($order) { |
| 123 | |||
| 124 | /** |
||
| 125 | * Save hidden for current user |
||
| 126 | * |
||
| 127 | * @NoAdminRequired |
||
| 128 | * @param $hidden string |
||
| 129 | * @return array response |
||
| 130 | */ |
||
| 131 | View Code Duplication | public function savePersonalHidden($hidden) { |
|
| 140 | |||
| 141 | /** |
||
| 142 | * Admin: save default hidden |
||
| 143 | * |
||
| 144 | * @param $hidden |
||
| 145 | * @return array response |
||
| 146 | */ |
||
| 147 | public function saveDefaultHidden($hidden) { |
||
| 153 | |||
| 154 | } |
||
| 155 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.