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 |
||
| 15 | class FaceController extends Controller { |
||
| 16 | |||
| 17 | private $rootFolder; |
||
| 18 | private $faceMapper; |
||
| 19 | private $userId; |
||
| 20 | |||
| 21 | View Code Duplication | public function __construct($AppName, IRequest $request, IRootFolder $rootFolder, FaceMapper $facemapper, $UserId) { |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @NoAdminRequired |
||
| 30 | */ |
||
| 31 | public function index() { |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @NoAdminRequired |
||
| 38 | * |
||
| 39 | * @param int $id |
||
| 40 | */ |
||
| 41 | public function find ($id) { |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @NoAdminRequired |
||
| 48 | * @NoCSRFRequired |
||
| 49 | */ |
||
| 50 | public function getThumb ($id) { |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @NoAdminRequired |
||
| 92 | * |
||
| 93 | */ |
||
| 94 | public function random () { |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @NoAdminRequired |
||
| 101 | * |
||
| 102 | * @param string $fullpath |
||
| 103 | */ |
||
| 104 | public function findFile ($fullpath) { |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @NoAdminRequired |
||
| 113 | * |
||
| 114 | * @param int $id |
||
| 115 | * @param string $name |
||
|
|
|||
| 116 | */ |
||
| 117 | View Code Duplication | public function updateName ($id, $newName) { |
|
| 124 | |||
| 125 | /** |
||
| 126 | * @NoAdminRequired |
||
| 127 | * |
||
| 128 | * @param int $id |
||
| 129 | */ |
||
| 130 | View Code Duplication | public function invalidate($id) { |
|
| 136 | |||
| 137 | } |
||
| 138 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.