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 |
||
| 9 | class PageController implements \Anax\DI\IInjectionAware |
||
| 10 | {
|
||
| 11 | use \Anax\DI\TInjectable, |
||
| 12 | \Anax\MVC\TRedirectHelpers; |
||
| 13 | |||
| 14 | public $page; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Initialize the controller. |
||
| 18 | * |
||
| 19 | * @return void |
||
| 20 | */ |
||
| 21 | public function initialize() |
||
| 26 | |||
| 27 | public function setupAction() |
||
| 33 | |||
| 34 | public function indexAction() |
||
| 38 | |||
| 39 | |||
| 40 | /** |
||
| 41 | * List all pages. |
||
| 42 | * |
||
| 43 | * @return void |
||
| 44 | */ |
||
| 45 | View Code Duplication | public function listAction() |
|
| 55 | |||
| 56 | /** |
||
| 57 | * Views page with with slug. |
||
| 58 | * |
||
| 59 | * @param int $slug of page to display |
||
| 60 | * |
||
| 61 | * @return void |
||
| 62 | */ |
||
| 63 | View Code Duplication | public function viewAction($slug = null) |
|
| 78 | |||
| 79 | /** |
||
| 80 | * Add new page. |
||
| 81 | * |
||
| 82 | * |
||
| 83 | * @return void |
||
| 84 | */ |
||
| 85 | View Code Duplication | public function addAction() |
|
| 100 | |||
| 101 | /** |
||
| 102 | * Edit a page. |
||
| 103 | * |
||
| 104 | * @param string $id of page to edit. |
||
| 105 | * |
||
| 106 | * @return void |
||
| 107 | */ |
||
| 108 | View Code Duplication | public function updateAction($id = null) |
|
| 129 | |||
| 130 | /** |
||
| 131 | * Delete page. |
||
| 132 | * |
||
| 133 | * @param integer $id of page to delete. |
||
| 134 | * |
||
| 135 | * @return void |
||
| 136 | */ |
||
| 137 | public function deleteAction($id = null) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Delete (soft) page. |
||
| 150 | * |
||
| 151 | * @param integer $id of page to delete. |
||
| 152 | * |
||
| 153 | * @return void |
||
| 154 | */ |
||
| 155 | View Code Duplication | public function softDeleteAction($id = null) |
|
| 170 | |||
| 171 | /** |
||
| 172 | * Restore (soft) deleted page. |
||
| 173 | * |
||
| 174 | * @param integer $id of page to restore. |
||
| 175 | * |
||
| 176 | * @return void |
||
| 177 | */ |
||
| 178 | View Code Duplication | public function restoreAction($id = null) |
|
| 191 | |||
| 192 | /** |
||
| 193 | * Activate page. |
||
| 194 | * |
||
| 195 | * @param integer $id of page to activate. |
||
| 196 | * |
||
| 197 | * @return void |
||
| 198 | */ |
||
| 199 | public function activateAction($id = null) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Inactivate page. |
||
| 215 | * |
||
| 216 | * @param integer $id of page to inactivate. |
||
| 217 | * |
||
| 218 | * @return void |
||
| 219 | */ |
||
| 220 | View Code Duplication | public function inactivateAction($id = null) |
|
| 235 | |||
| 236 | /** |
||
| 237 | * List all active and not deleted pages. |
||
| 238 | * |
||
| 239 | * @return void |
||
| 240 | */ |
||
| 241 | View Code Duplication | public function activeAction() |
|
| 254 | |||
| 255 | /** |
||
| 256 | * List all inactive pages. |
||
| 257 | * |
||
| 258 | * @return void |
||
| 259 | */ |
||
| 260 | View Code Duplication | public function inactiveAction() |
|
| 272 | |||
| 273 | /** |
||
| 274 | * List all deleted pages. |
||
| 275 | * |
||
| 276 | * @return void |
||
| 277 | */ |
||
| 278 | View Code Duplication | public function trashAction() |
|
| 290 | |||
| 291 | } |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.