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 | View Code Duplication | class IndexViewCompiler extends AbstractViewCompiler |
|
12 | { |
||
13 | /** |
||
14 | * Compiles the index view. |
||
15 | * |
||
16 | * @param $stub |
||
17 | * @param $modelName |
||
18 | * @param $modelData |
||
19 | * @param $scaffolderConfig |
||
20 | * @param $hash |
||
21 | * @param null $extra |
||
22 | * |
||
23 | * @return string |
||
24 | */ |
||
25 | public function compile($stub, $modelName, $modelData, $scaffolderConfig, $hash, $extra = null) |
||
43 | |||
44 | /** |
||
45 | * Store the compiled stub. |
||
46 | * |
||
47 | * @param $modelName |
||
48 | * @param $scaffolderConfig |
||
49 | * @param $compiled |
||
50 | * @param FileToCompile $fileToCompile |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) |
||
76 | |||
77 | /** |
||
78 | * Datatable fields. |
||
79 | * |
||
80 | * @param $modelName |
||
81 | * @param $modelData |
||
82 | * |
||
83 | * @return $this |
||
84 | */ |
||
85 | private function addDatatableFields($modelName, $modelData) |
||
111 | |||
112 | /** |
||
113 | * Set index table headers. |
||
114 | * |
||
115 | * @param $modelData |
||
116 | * |
||
117 | * @return $this |
||
118 | */ |
||
119 | private function setTableHeaders($modelData) |
||
145 | |||
146 | /** |
||
147 | * Replace the prefix. |
||
148 | * |
||
149 | * @param $prefix |
||
150 | * |
||
151 | * @return $this |
||
152 | */ |
||
153 | private function replaceRoutePrefix($prefix) |
||
159 | } |