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) |
|
99 | |||
100 | /** |
||
101 | * setFullRepositoryInterface. |
||
102 | * |
||
103 | * @param string $value |
||
104 | * @return $this |
||
105 | */ |
||
106 | 3 | View Code Duplication | public function setFullRepositoryInterface($value) |
115 | |||
116 | /** |
||
117 | * setFullRepositoryClass. |
||
118 | * |
||
119 | * @param string $value |
||
120 | * @return $this |
||
121 | */ |
||
122 | 3 | public function setFullRepositoryClass($value) |
|
132 | |||
133 | /** |
||
134 | * setFullModelClass. |
||
135 | * |
||
136 | * @param string $value |
||
137 | * @return $this |
||
138 | */ |
||
139 | 4 | public function setFullModelClass($value) |
|
151 | |||
152 | /** |
||
153 | * setFullPresenterClass. |
||
154 | * |
||
155 | * @param string $value |
||
156 | * @return $this |
||
157 | */ |
||
158 | 1 | View Code Duplication | public function setFullPresenterClass($value) |
167 | |||
168 | /** |
||
169 | * setFullRequestClass. |
||
170 | * |
||
171 | * @param string $value |
||
172 | * @return $this |
||
173 | */ |
||
174 | 3 | View Code Duplication | public function setFullRequestClass($value) |
183 | |||
184 | /** |
||
185 | * setFullControllerClass. |
||
186 | * |
||
187 | * @param string $value |
||
188 | * @return $this |
||
189 | */ |
||
190 | 2 | public function setFullControllerClass($value) |
|
204 | |||
205 | /** |
||
206 | * set. |
||
207 | * |
||
208 | * @param string $value |
||
209 | * @return $this |
||
210 | */ |
||
211 | 9 | public function set($key, $value = null, $replace = true) |
|
229 | |||
230 | /** |
||
231 | * get. |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | 7 | public function get($key) |
|
239 | |||
240 | /** |
||
241 | * remove. |
||
242 | * |
||
243 | * @param string $key |
||
244 | * @return bool |
||
245 | */ |
||
246 | 2 | public function remove($key) |
|
250 | |||
251 | /** |
||
252 | * render. |
||
253 | * |
||
254 | * @param string $stub |
||
255 | * @param bool $orderedUse |
||
256 | * @return string |
||
257 | */ |
||
258 | 8 | public function render($stub, $orderedUse = true) |
|
268 | |||
269 | /** |
||
270 | * renderServiceProvider. |
||
271 | * |
||
272 | * @param string $content |
||
273 | * @return string |
||
274 | */ |
||
275 | 1 | public function renderServiceProvider($content) |
|
312 | |||
313 | /** |
||
314 | * replaceServieProviderCallback. |
||
315 | * |
||
316 | * @param array $match |
||
317 | * @return string |
||
318 | */ |
||
319 | 1 | protected function replaceServieProviderCallback($match) |
|
335 | |||
336 | /** |
||
337 | * getNamespace. |
||
338 | * |
||
339 | * @param string $name |
||
340 | * @return string |
||
341 | */ |
||
342 | 9 | protected function getNamespace($name) |
|
346 | |||
347 | /** |
||
348 | * format. |
||
349 | * |
||
350 | * @param string $content |
||
351 | * @param bool $orderedUse |
||
352 | * @return string |
||
353 | */ |
||
354 | 9 | protected function format($content, $orderedUse = true) |
|
362 | } |
||
363 |