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 | 4 | 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() { |
| 66 | |||
| 67 | View Code Duplication | public function personalIndex() { |
|
| 79 | |||
| 80 | /** |
||
| 81 | * Admin: save default order |
||
| 82 | * |
||
| 83 | * @param $order |
||
| 84 | * @return array response |
||
| 85 | */ |
||
| 86 | 1 | public function saveDefaultOrder($order) { |
|
| 92 | |||
| 93 | /** |
||
| 94 | * Return order for current user |
||
| 95 | * |
||
| 96 | * @NoAdminRequired |
||
| 97 | * @return array response |
||
| 98 | 1 | */ |
|
| 99 | 1 | public function getOrder() { |
|
| 103 | 1 | ||
| 104 | /** |
||
| 105 | 1 | * Save order for current user |
|
| 106 | * |
||
| 107 | * @NoAdminRequired |
||
| 108 | * @param $order string |
||
| 109 | * @return array response |
||
| 110 | */ |
||
| 111 | public function savePersonal($order) { |
||
| 120 | |||
| 121 | } |
||
| 122 |
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.