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 |
||
| 8 | class Table extends Component |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Router. |
||
| 12 | * |
||
| 13 | * @var \Illuminate\Routing\Router |
||
| 14 | */ |
||
| 15 | protected $router; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Table ID. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $id; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Create a new component instance. |
||
| 26 | * |
||
| 27 | * @param string $id |
||
| 28 | * @param \Illuminate\Routing\Router $router |
||
| 29 | * |
||
| 30 | * @return void |
||
|
|
|||
| 31 | */ |
||
| 32 | public function __construct(Router $router, $id = 'routes') |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Get the view / contents that represent the component. |
||
| 40 | * |
||
| 41 | * @return \Illuminate\View\View |
||
| 42 | */ |
||
| 43 | public function render() |
||
| 52 | |||
| 53 | protected function getRoutes() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Get route middleware. |
||
| 78 | * |
||
| 79 | * @param \Illuminate\Routing\Route $route |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | protected function getRouteMiddleware($route) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Perform a regular expression match. |
||
| 92 | * |
||
| 93 | * @param array $patterns |
||
| 94 | * @param string $subject |
||
| 95 | * |
||
| 96 | * @return bool |
||
| 97 | */ |
||
| 98 | View Code Duplication | protected function matches($patterns, $subject) |
|
| 112 | } |
||
| 113 |
Adding a
@returnannotation 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.