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 |
||
19 | class Admin |
||
20 | { |
||
21 | /** |
||
22 | * The Laravel admin version. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | const VERSION = '1.5.19'; |
||
27 | |||
28 | /** |
||
29 | * @var Navbar |
||
30 | */ |
||
31 | protected $navbar; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | public static $script = []; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | public static $css = []; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | public static $js = []; |
||
47 | |||
48 | /** |
||
49 | * @var array |
||
50 | */ |
||
51 | public static $extensions = []; |
||
52 | |||
53 | /** |
||
54 | * Returns the long version of Laravel-admin. |
||
55 | * |
||
56 | * @return string The long application version |
||
57 | */ |
||
58 | public static function getLongVersion() |
||
62 | |||
63 | /** |
||
64 | * @param $model |
||
65 | * @param Closure $callable |
||
66 | * |
||
67 | * @return \Encore\Admin\Grid |
||
68 | */ |
||
69 | public function grid($model, Closure $callable) |
||
73 | |||
74 | /** |
||
75 | * @param $model |
||
76 | * @param Closure $callable |
||
77 | * |
||
78 | * @return \Encore\Admin\Form |
||
79 | */ |
||
80 | public function form($model, Closure $callable) |
||
84 | |||
85 | /** |
||
86 | * Build a tree. |
||
87 | * |
||
88 | * @param $model |
||
89 | * |
||
90 | * @return \Encore\Admin\Tree |
||
91 | */ |
||
92 | public function tree($model, Closure $callable = null) |
||
96 | |||
97 | /** |
||
98 | * Build show page. |
||
99 | * |
||
100 | * @param $model |
||
101 | * @param mixed $callable |
||
102 | * |
||
103 | * @return Show |
||
104 | */ |
||
105 | public function show($model, $callable = null) |
||
109 | |||
110 | /** |
||
111 | * @param Closure $callable |
||
112 | * |
||
113 | * @return \Encore\Admin\Layout\Content |
||
114 | */ |
||
115 | public function content(Closure $callable = null) |
||
119 | |||
120 | /** |
||
121 | * @param $model |
||
122 | * |
||
123 | * @return mixed |
||
124 | */ |
||
125 | public function getModel($model) |
||
137 | |||
138 | /** |
||
139 | * Add css or get all css. |
||
140 | * |
||
141 | * @param null $css |
||
142 | * |
||
143 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|void |
||
144 | */ |
||
145 | View Code Duplication | public static function css($css = null) |
|
159 | |||
160 | /** |
||
161 | * Add js or get all js. |
||
162 | * |
||
163 | * @param null $js |
||
164 | * |
||
165 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|void |
||
166 | */ |
||
167 | View Code Duplication | public static function js($js = null) |
|
181 | |||
182 | /** |
||
183 | * @param string $script |
||
184 | * |
||
185 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|void |
||
186 | */ |
||
187 | public static function script($script = '') |
||
197 | |||
198 | /** |
||
199 | * Left sider-bar menu. |
||
200 | * |
||
201 | * @return array |
||
202 | */ |
||
203 | public function menu() |
||
207 | |||
208 | /** |
||
209 | * Get admin title. |
||
210 | * |
||
211 | * @return Config |
||
212 | */ |
||
213 | public function title() |
||
217 | |||
218 | /** |
||
219 | * Get current login user. |
||
220 | * |
||
221 | * @return mixed |
||
222 | */ |
||
223 | public function user() |
||
227 | |||
228 | /** |
||
229 | * Set navbar. |
||
230 | * |
||
231 | * @param Closure|null $builder |
||
232 | * |
||
233 | * @return Navbar |
||
234 | */ |
||
235 | public function navbar(Closure $builder = null) |
||
243 | |||
244 | /** |
||
245 | * Get navbar object. |
||
246 | * |
||
247 | * @return \Encore\Admin\Widgets\Navbar |
||
248 | */ |
||
249 | public function getNavbar() |
||
257 | |||
258 | /** |
||
259 | * Register the auth routes. |
||
260 | * |
||
261 | * @return void |
||
262 | */ |
||
263 | public function registerAuthRoutes() |
||
291 | |||
292 | /** |
||
293 | * Extend a extension. |
||
294 | * |
||
295 | * @param string $name |
||
296 | * @param string $class |
||
297 | * |
||
298 | * @return void |
||
299 | */ |
||
300 | public static function extend($name, $class) |
||
304 | |||
305 | /* |
||
306 | * Disable Pjax for current Request |
||
307 | * |
||
308 | * @return void |
||
309 | */ |
||
310 | public function disablePjax() |
||
318 | } |
||
319 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.