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 |
||
11 | class LocalizerMiddleware |
||
12 | { |
||
13 | /** |
||
14 | * This function checks if language to set is an allowed lang of config. |
||
15 | * |
||
16 | * @param string $lang |
||
17 | **/ |
||
18 | private function setIfAllowed($lang) |
||
27 | |||
28 | /** |
||
29 | * This function checks if user is logged in, and loads the prefered language. |
||
30 | * |
||
31 | * @param string $lang |
||
|
|||
32 | **/ |
||
33 | public function setLang() |
||
60 | |||
61 | /** |
||
62 | * Handle an incoming request. |
||
63 | * |
||
64 | * @param \Illuminate\Http\Request $request |
||
65 | * @param \Closure $next |
||
66 | * |
||
67 | * @return mixed |
||
68 | */ |
||
69 | public function handle($request, Closure $next) |
||
75 | } |
||
76 |
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
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.