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 |
||
10 | class Generator |
||
11 | { |
||
12 | /** |
||
13 | * $filesystem. |
||
14 | * |
||
15 | * @var \Illuminate\Filesystem\Filesystem |
||
16 | */ |
||
17 | protected $filesystem; |
||
18 | |||
19 | /** |
||
20 | * $useSortFixer. |
||
21 | * |
||
22 | * @var \Recca0120\Generator\Fixers\UseSortFixer |
||
23 | */ |
||
24 | protected $useSortFixer; |
||
25 | |||
26 | /** |
||
27 | * $attributes. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $attributes = []; |
||
32 | |||
33 | /** |
||
34 | * __construct. |
||
35 | * |
||
36 | * @param \Illuminate\Filesystem\Filesystem $filesystem |
||
37 | * @param \Recca0120\Generator\Fixers\UseSortFixer $useSortFixer |
||
38 | */ |
||
39 | 9 | public function __construct(Filesystem $filesystem = null, UseSortFixer $useSortFixer = null) |
|
45 | |||
46 | /** |
||
47 | * parseAttribute. |
||
48 | * |
||
49 | * @param string $value |
||
50 | * @return array |
||
51 | */ |
||
52 | 9 | protected function parseAttribute($value) |
|
81 | |||
82 | /** |
||
83 | * setFullBaseClass. |
||
84 | * |
||
85 | * @param string $value |
||
86 | * @return $this |
||
87 | */ |
||
88 | 7 | public function setFullBaseClass($value) |
|
100 | |||
101 | /** |
||
102 | * setFullRepositoryInterface. |
||
103 | * |
||
104 | * @param string $value |
||
105 | * @return $this |
||
106 | */ |
||
107 | 3 | View Code Duplication | public function setFullRepositoryInterface($value) |
116 | |||
117 | /** |
||
118 | * setFullRepositoryClass. |
||
119 | * |
||
120 | * @param string $value |
||
121 | * @return $this |
||
122 | */ |
||
123 | 3 | public function setFullRepositoryClass($value) |
|
133 | |||
134 | /** |
||
135 | * setFullModelClass. |
||
136 | * |
||
137 | * @param string $value |
||
138 | * @return $this |
||
139 | */ |
||
140 | 4 | public function setFullModelClass($value) |
|
152 | |||
153 | /** |
||
154 | * setFullPresenterClass. |
||
155 | * |
||
156 | * @param string $value |
||
157 | * @return $this |
||
158 | */ |
||
159 | 1 | View Code Duplication | public function setFullPresenterClass($value) |
168 | |||
169 | /** |
||
170 | * setFullRequestClass. |
||
171 | * |
||
172 | * @param string $value |
||
173 | * @return $this |
||
174 | */ |
||
175 | 3 | View Code Duplication | public function setFullRequestClass($value) |
184 | |||
185 | /** |
||
186 | * setFullControllerClass. |
||
187 | * |
||
188 | * @param string $value |
||
189 | * @return $this |
||
190 | */ |
||
191 | 2 | public function setFullControllerClass($value) |
|
205 | |||
206 | /** |
||
207 | * set. |
||
208 | * |
||
209 | * @param string $value |
||
210 | * @return $this |
||
211 | */ |
||
212 | 9 | public function set($key, $value = null, $replace = true) |
|
226 | |||
227 | /** |
||
228 | * get. |
||
229 | * |
||
230 | * @return string |
||
231 | */ |
||
232 | 7 | public function get($key) |
|
236 | |||
237 | /** |
||
238 | * remove. |
||
239 | * |
||
240 | * @param string $key |
||
241 | * @return bool |
||
242 | */ |
||
243 | 2 | public function remove($key) |
|
247 | |||
248 | /** |
||
249 | * render. |
||
250 | * |
||
251 | * @param string $stub |
||
252 | * @param bool $orderedUses |
||
253 | * @return string |
||
254 | */ |
||
255 | 8 | public function render($stub, $orderedUses = true) |
|
264 | |||
265 | /** |
||
266 | * renderServiceProvider. |
||
267 | * |
||
268 | * @param string $content |
||
269 | * @return string |
||
270 | */ |
||
271 | 1 | public function renderServiceProvider($content) |
|
308 | |||
309 | /** |
||
310 | * replaceServieProviderCallback. |
||
311 | * |
||
312 | * @param array $match |
||
313 | * @return string |
||
314 | */ |
||
315 | 1 | protected function replaceServieProviderCallback($match) |
|
331 | |||
332 | /** |
||
333 | * getNamespace. |
||
334 | * |
||
335 | * @param string $name |
||
336 | * @return string |
||
337 | */ |
||
338 | 9 | protected function getNamespace($name) |
|
342 | |||
343 | /** |
||
344 | * orderedUses. |
||
345 | * |
||
346 | * @param string $content |
||
347 | * @return string |
||
348 | */ |
||
349 | 9 | protected function orderedUses($content) |
|
355 | } |
||
356 |