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 |
||
| 12 | class LocalizerMiddleware |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * This function checks if language to set is an allowed lang of config. |
||
| 16 | * |
||
| 17 | * @param string $lang |
||
| 18 | **/ |
||
| 19 | private function setIfAllowed($lang) |
||
| 20 | { |
||
| 21 | $allowedLangs = array_keys(Localizer::allowedLanguages()); |
||
| 22 | if (config('localizer.block_unallowed_langs') && !in_array($lang, $allowedLangs)) { |
||
| 23 | $lang = $allowedLangs[0]; |
||
| 24 | } |
||
| 25 | |||
| 26 | App::setLocale($lang); |
||
| 27 | if (config('localizer.carbon')) { |
||
| 28 | Carbon::setLocale($lang); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * This function checks if user is logged in, and loads the prefered language. |
||
| 34 | * |
||
| 35 | * @param string $lang |
||
|
|
|||
| 36 | **/ |
||
| 37 | public function setLang($request) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Handle an incoming request. |
||
| 67 | * |
||
| 68 | * @param \Illuminate\Http\Request $request |
||
| 69 | * @param \Closure $next |
||
| 70 | * |
||
| 71 | * @return mixed |
||
| 72 | */ |
||
| 73 | public function handle($request, Closure $next) |
||
| 79 | } |
||
| 80 |
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.