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 \Illuminate\Routing\Router $router |
||
24 | * |
||
25 | * @return void |
||
|
|||
26 | */ |
||
27 | 1 | public function __construct(Router $router) |
|
31 | |||
32 | /** |
||
33 | * Render routes. |
||
34 | * |
||
35 | * @return \Illuminate\View\View |
||
36 | */ |
||
37 | 1 | public function __invoke() |
|
63 | |||
64 | /** |
||
65 | * Get route middleware. |
||
66 | * |
||
67 | * @param \Illuminate\Routing\Route $route |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | 1 | protected function getRouteMiddleware($route) |
|
79 | |||
80 | /** |
||
81 | * Perform a regular expression match. |
||
82 | * |
||
83 | * @param array $patterns |
||
84 | * @param string $subject |
||
85 | * |
||
86 | * @return bool |
||
87 | */ |
||
88 | 1 | View Code Duplication | protected function matches($patterns, $subject) |
102 | } |
||
103 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.