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) |
|
82 | |||
83 | /** |
||
84 | * setFullBaseClass. |
||
85 | * |
||
86 | * @param string $value |
||
87 | * @return $this |
||
88 | */ |
||
89 | 7 | public function setFullBaseClass($value) |
|
101 | |||
102 | /** |
||
103 | * setFullRepositoryInterface. |
||
104 | * |
||
105 | * @param string $value |
||
106 | * @return $this |
||
107 | */ |
||
108 | 3 | View Code Duplication | public function setFullRepositoryInterface($value) |
117 | |||
118 | /** |
||
119 | * setFullRepositoryClass. |
||
120 | * |
||
121 | * @param string $value |
||
122 | * @return $this |
||
123 | */ |
||
124 | 3 | public function setFullRepositoryClass($value) |
|
134 | |||
135 | /** |
||
136 | * setFullModelClass. |
||
137 | * |
||
138 | * @param string $value |
||
139 | * @return $this |
||
140 | */ |
||
141 | 4 | public function setFullModelClass($value) |
|
153 | |||
154 | /** |
||
155 | * setFullPresenterClass. |
||
156 | * |
||
157 | * @param string $value |
||
158 | * @return $this |
||
159 | */ |
||
160 | 1 | View Code Duplication | public function setFullPresenterClass($value) |
169 | |||
170 | /** |
||
171 | * setFullRequestClass. |
||
172 | * |
||
173 | * @param string $value |
||
174 | * @return $this |
||
175 | */ |
||
176 | 3 | View Code Duplication | public function setFullRequestClass($value) |
185 | |||
186 | /** |
||
187 | * setFullControllerClass. |
||
188 | * |
||
189 | * @param string $value |
||
190 | * @return $this |
||
191 | */ |
||
192 | 2 | public function setFullControllerClass($value) |
|
206 | |||
207 | /** |
||
208 | * set. |
||
209 | * |
||
210 | * @param string $value |
||
211 | * @return $this |
||
212 | */ |
||
213 | 9 | public function set($key, $value = null, $replace = true) |
|
227 | |||
228 | /** |
||
229 | * get. |
||
230 | * |
||
231 | * @return string |
||
232 | */ |
||
233 | 7 | public function get($key) |
|
237 | |||
238 | /** |
||
239 | * remove. |
||
240 | * |
||
241 | * @param string $key |
||
242 | * @return bool |
||
243 | */ |
||
244 | 2 | public function remove($key) |
|
248 | |||
249 | /** |
||
250 | * render. |
||
251 | * |
||
252 | * @param string $stub |
||
253 | * @param bool $orderedUses |
||
254 | * @return string |
||
255 | */ |
||
256 | 8 | public function render($stub, $orderedUses = true) |
|
265 | |||
266 | /** |
||
267 | * renderServiceProvider. |
||
268 | * |
||
269 | * @param string $content |
||
270 | * @return string |
||
271 | */ |
||
272 | 1 | public function renderServiceProvider($content) |
|
309 | |||
310 | /** |
||
311 | * replaceServieProviderCallback. |
||
312 | * |
||
313 | * @param array $match |
||
314 | * @return string |
||
315 | */ |
||
316 | 1 | protected function replaceServieProviderCallback($match) |
|
332 | |||
333 | /** |
||
334 | * getNamespace. |
||
335 | * |
||
336 | * @param string $name |
||
337 | * @return string |
||
338 | */ |
||
339 | 9 | protected function getNamespace($name) |
|
343 | |||
344 | /** |
||
345 | * orderedUses. |
||
346 | * |
||
347 | * @param string $content |
||
348 | * @return string |
||
349 | */ |
||
350 | 9 | protected function orderedUses($content) |
|
356 | } |
||
357 |