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 CreateViewCompiler extends AbstractViewCompiler |
|
13 | { |
||
14 | use InputTypeResolverTrait; |
||
15 | |||
16 | /** |
||
17 | * Compiles the create 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) |
||
45 | |||
46 | /** |
||
47 | * Store the compiled stub. |
||
48 | * |
||
49 | * @param $modelName |
||
50 | * @param $scaffolderConfig |
||
51 | * @param $compiled |
||
52 | * @param FileToCompile $fileToCompile |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | protected function store($modelName, $scaffolderConfig, $compiled, FileToCompile $fileToCompile) |
||
78 | |||
79 | /** |
||
80 | * Add fields to the create view. |
||
81 | * |
||
82 | * @param $modelData |
||
83 | * |
||
84 | * @return $this |
||
85 | */ |
||
86 | private function addFields($modelData) |
||
108 | |||
109 | /** |
||
110 | * Replace the prefix. |
||
111 | * |
||
112 | * @param $prefix |
||
113 | * |
||
114 | * @return $this |
||
115 | */ |
||
116 | private function replaceRoutePrefix($prefix) |
||
122 | } |