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 |
||
12 | View Code Duplication | class EditViewCompiler extends AbstractViewCompiler |
|
13 | { |
||
14 | use InputTypeResolverTrait; |
||
15 | |||
16 | /** |
||
17 | * Compiles the edit view. |
||
18 | * |
||
19 | * @param $stub |
||
20 | * @param $modelName |
||
21 | * @param $modelData |
||
22 | * @param $scaffolderConfig |
||
23 | * @param $hash |
||
24 | * @param null $extra |
||
25 | * |
||
26 | * @return string |
||
27 | */ |
||
28 | public function compile($stub, $modelName, $modelData, $scaffolderConfig, $hash, $extra = null) |
||
46 | |||
47 | /** |
||
48 | * Store the compiled stub. |
||
49 | * |
||
50 | * @param $modelName |
||
51 | * @param $scaffolderConfig |
||
52 | * @param $compiled |
||
53 | * @param FileToCompile $fileToCompile |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) |
||
79 | |||
80 | /** |
||
81 | * Add fields to the edit view. |
||
82 | * |
||
83 | * @param $modelData |
||
84 | * |
||
85 | * @return $this |
||
86 | */ |
||
87 | private function addFields($modelData) |
||
109 | |||
110 | /** |
||
111 | * Replace the prefix. |
||
112 | * |
||
113 | * @param $prefix |
||
114 | * |
||
115 | * @return $this |
||
116 | */ |
||
117 | private function replaceRoutePrefix($prefix) |
||
123 | |||
124 | /** |
||
125 | * Replace the primary key. |
||
126 | * |
||
127 | * @param $modelData |
||
128 | */ |
||
129 | private function replacePrimaryKey($modelData) |
||
146 | } |