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 RouteListController extends Controller |
||
12 | { |
||
13 | /** |
||
14 | * Router. |
||
15 | * |
||
16 | * @var \Illuminate\Routing\Router |
||
17 | */ |
||
18 | protected $router; |
||
19 | |||
20 | /** |
||
21 | * Create a controller instance. |
||
22 | * |
||
23 | * @param string $id |
||
|
|||
24 | * @param Router $router |
||
25 | * |
||
26 | * @return void |
||
27 | */ |
||
28 | public function __construct(Router $router) |
||
32 | |||
33 | /** |
||
34 | * Render routes. |
||
35 | * |
||
36 | * @return \Illuminate\Http\Response |
||
37 | */ |
||
38 | public function __invoke() |
||
64 | |||
65 | /** |
||
66 | * Get route middleware. |
||
67 | * |
||
68 | * @param \Illuminate\Routing\Route $route |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | protected function getRouteMiddleware($route) |
||
78 | |||
79 | /** |
||
80 | * Perform a regular expression match. |
||
81 | * |
||
82 | * @param array $patterns |
||
83 | * @param string $subject |
||
84 | * |
||
85 | * @return bool |
||
86 | */ |
||
87 | View Code Duplication | protected function matches($patterns, $subject) |
|
101 | } |
||
102 |
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.