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 |
||
14 | class MakeMenu extends Command |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Path to menu file. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $menu_path = 'config/menu.php'; |
||
23 | |||
24 | /** |
||
25 | * Compiler for stub file. |
||
26 | * |
||
27 | * @var StubFileCompiler |
||
28 | */ |
||
29 | protected $compiler; |
||
30 | |||
31 | /** |
||
32 | * Compiler for stub file. |
||
33 | * |
||
34 | * @var Filesystem |
||
35 | */ |
||
36 | protected $filesystem; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | protected static $lookup = [ |
||
42 | 'regular' => RegularMenu::class, |
||
43 | // 'another' => AnotherMenu::class, |
||
|
|||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * The name and signature of the console command. |
||
48 | */ |
||
49 | protected $signature = 'make:menu {link : The menu link} {name? : The menu name} |
||
50 | {--t|type=regular : Type of menu to create (regular,todo)}'; |
||
51 | |||
52 | /** |
||
53 | * The console command description. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $description = 'Insert a menu to config/menu file'; |
||
58 | |||
59 | /** |
||
60 | * AdminLTERoute constructor. |
||
61 | * |
||
62 | * @param StubFileCompiler $compiler |
||
63 | * @param Filesystem $filesystem |
||
64 | */ |
||
65 | public function __construct(StubFileCompiler $compiler, Filesystem $filesystem) |
||
71 | |||
72 | /** |
||
73 | * Execute the console command. |
||
74 | */ |
||
75 | public function handle() |
||
84 | |||
85 | /** |
||
86 | * Get mountpoint. |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | protected function mountpoint() |
||
94 | |||
95 | /** |
||
96 | * Destination route file. |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | protected function destinationFile() |
||
104 | |||
105 | /** |
||
106 | * Crete tmp file with route to add. |
||
107 | * |
||
108 | * @return mixed |
||
109 | */ |
||
110 | protected function createTmpFileWithMenu() |
||
116 | |||
117 | /** |
||
118 | * Get route code to insert depending on type. |
||
119 | * |
||
120 | * @return mixed |
||
121 | */ |
||
122 | View Code Duplication | protected function getMenuCode() |
|
136 | |||
137 | /** |
||
138 | * Get path from file resource. |
||
139 | * |
||
140 | * @param $tmpfile |
||
141 | * @return mixed |
||
142 | */ |
||
143 | protected function getPath($tmpfile) |
||
147 | |||
148 | /** |
||
149 | * Get method. |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | View Code Duplication | protected function method() |
|
160 | |||
161 | /** |
||
162 | * Get the link name. |
||
163 | * |
||
164 | * @return array|string |
||
165 | */ |
||
166 | protected function name() |
||
173 | |||
174 | /** |
||
175 | * Process input. |
||
176 | */ |
||
177 | protected function processInput() |
||
181 | |||
182 | /** |
||
183 | * Execute post actions (if exists) |
||
184 | */ |
||
185 | protected function postActions() |
||
189 | } |
||
190 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.