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 |
||
31 | class LocalDriver extends DriverAbstract |
||
32 | { |
||
33 | use LocalDirTrait; |
||
34 | |||
35 | /** |
||
36 | * driver root |
||
37 | * |
||
38 | * @var string |
||
39 | * @access protected |
||
40 | */ |
||
41 | protected $root; |
||
42 | |||
43 | /** |
||
44 | * @param string $rootDir |
||
45 | * @throws LogicException |
||
46 | * @access public |
||
47 | */ |
||
48 | public function __construct(/*# string */ $rootDir) |
||
58 | |||
59 | /** |
||
60 | * {@inheritDoc} |
||
61 | */ |
||
62 | protected function realPath(/*# string */ $path)/*# : string */ |
||
67 | |||
68 | /** |
||
69 | * {@inheritDoc} |
||
70 | */ |
||
71 | protected function realExists(/*# string */ $realPath)/*# : bool */ |
||
75 | |||
76 | /** |
||
77 | * {@inheritDoc} |
||
78 | */ |
||
79 | protected function openReadStream(/*# string */ $realPath) |
||
92 | |||
93 | /** |
||
94 | * {@inheritDoc} |
||
95 | */ |
||
96 | View Code Duplication | protected function readFile(/*# string */ $realPath) |
|
110 | |||
111 | /** |
||
112 | * {@inheritDoc} |
||
113 | */ |
||
114 | protected function getRealMeta(/*# string */ $realPath)/*# : array */ |
||
132 | |||
133 | /** |
||
134 | * {@inheritDoc} |
||
135 | */ |
||
136 | protected function ensurePath(/*# string */ $realPath)/*# : bool */ |
||
144 | |||
145 | /** |
||
146 | * {@inheritDoc} |
||
147 | */ |
||
148 | View Code Duplication | protected function writeStream( |
|
163 | |||
164 | /** |
||
165 | * {@inheritDoc} |
||
166 | */ |
||
167 | View Code Duplication | protected function writeFile( |
|
182 | |||
183 | /** |
||
184 | * {@inheritDoc} |
||
185 | */ |
||
186 | protected function setRealMeta( |
||
201 | |||
202 | /** |
||
203 | * {@inheritDoc} |
||
204 | */ |
||
205 | protected function renameFile( |
||
211 | |||
212 | /** |
||
213 | * {@inheritDoc} |
||
214 | */ |
||
215 | protected function copyFile( |
||
221 | |||
222 | /** |
||
223 | * {@inheritDoc} |
||
224 | */ |
||
225 | protected function deleteFile(/*# string */ $realPath)/*# : bool */ |
||
229 | |||
230 | /** |
||
231 | * Rename tmpfile |
||
232 | * |
||
233 | * @param string $tmpFile |
||
234 | * @param string $realPath |
||
235 | * @return bool |
||
236 | * @access protected |
||
237 | */ |
||
238 | protected function renameTempFile( |
||
251 | } |
||
252 |