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 |
||
27 | class ProjectController extends Controller |
||
28 | { |
||
29 | use DispatchesJobs; |
||
30 | |||
31 | /** |
||
32 | * Array of sub-menu items. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $subMenu = []; |
||
37 | |||
38 | /** |
||
39 | * Creates a new project controller instance. |
||
40 | * |
||
41 | * @return void |
||
|
|||
42 | */ |
||
43 | public function __construct() |
||
71 | |||
72 | /** |
||
73 | * Shows the projects view. |
||
74 | * |
||
75 | * @return \Illuminate\View\View |
||
76 | */ |
||
77 | View Code Duplication | public function indexAction() |
|
87 | |||
88 | /** |
||
89 | * Shows the starred projects view. |
||
90 | * |
||
91 | * @return \Illuminate\View\View |
||
92 | */ |
||
93 | public function starredAction() |
||
105 | } |
||
106 |
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.