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) |
|
221 | |||
222 | /** |
||
223 | * get. |
||
224 | * |
||
225 | * @return string |
||
226 | */ |
||
227 | 7 | public function get($key) |
|
231 | |||
232 | /** |
||
233 | * remove. |
||
234 | * |
||
235 | * @param string $key |
||
236 | * @return bool |
||
237 | */ |
||
238 | 2 | public function remove($key) |
|
242 | |||
243 | /** |
||
244 | * render. |
||
245 | * |
||
246 | * @param string $stub |
||
247 | * @param bool $orderedUse |
||
248 | * @return string |
||
249 | */ |
||
250 | 8 | public function render($stub, $orderedUse = true) |
|
260 | |||
261 | /** |
||
262 | * renderServiceProvider. |
||
263 | * |
||
264 | * @param string $content |
||
265 | * @return string |
||
266 | */ |
||
267 | 1 | public function renderServiceProvider($content) |
|
304 | |||
305 | /** |
||
306 | * replaceServieProviderCallback. |
||
307 | * |
||
308 | * @param array $match |
||
309 | * @return string |
||
310 | */ |
||
311 | 1 | protected function replaceServieProviderCallback($match) |
|
327 | |||
328 | /** |
||
329 | * getNamespace. |
||
330 | * |
||
331 | * @param string $name |
||
332 | * @return string |
||
333 | */ |
||
334 | 9 | protected function getNamespace($name) |
|
338 | |||
339 | /** |
||
340 | * format. |
||
341 | * |
||
342 | * @param string $content |
||
343 | * @param bool $orderedUse |
||
344 | * @return string |
||
345 | */ |
||
346 | 9 | protected function format($content, $orderedUse = true) |
|
354 | } |
||
355 |