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 |
||
42 | class Path extends ObjectAbstract implements PathInterface, ErrorAwareInterface, FilesystemAwareInterface, ExtensionAwareInterface |
||
43 | { |
||
44 | use FilesystemAwareTrait, ErrorAwareTrait, ExtensionAwareTrait; |
||
45 | |||
46 | /** |
||
47 | * Full path with mount point |
||
48 | * |
||
49 | * @var string |
||
50 | * @access protected |
||
51 | */ |
||
52 | protected $full; |
||
53 | |||
54 | /** |
||
55 | * relative path without mount point prefix |
||
56 | * |
||
57 | * @var string |
||
58 | * @access protected |
||
59 | */ |
||
60 | protected $path; |
||
61 | |||
62 | /** |
||
63 | * Instantiate the path object |
||
64 | * |
||
65 | * @param string $full full path |
||
66 | * @param string $path relative path without mount point |
||
67 | * @param FilesystemInterface $filesystem |
||
68 | * @access public |
||
69 | * @api |
||
70 | */ |
||
71 | public function __construct( |
||
80 | |||
81 | /** |
||
82 | * {@inheritDoc} |
||
83 | */ |
||
84 | public function exists()/*# : bool */ |
||
94 | |||
95 | /** |
||
96 | * {@inheritDoc} |
||
97 | */ |
||
98 | View Code Duplication | public function getContent(/*# bool */ $stream = false) |
|
107 | |||
108 | /** |
||
109 | * {@inheritDoc} |
||
110 | */ |
||
111 | public function getMeta()/*# : array */ |
||
121 | |||
122 | /** |
||
123 | * {@inheritDoc} |
||
124 | */ |
||
125 | public function getPath()/*# : string */ |
||
129 | |||
130 | /** |
||
131 | * {@inheritDoc} |
||
132 | */ |
||
133 | public function getFullPath()/*# : string */ |
||
137 | |||
138 | /** |
||
139 | * {@inheritDoc} |
||
140 | */ |
||
141 | public function setContent($content)/*# : bool */ |
||
152 | |||
153 | /** |
||
154 | * {@inheritDoc} |
||
155 | */ |
||
156 | public function setMeta(array $meta)/*# : bool */ |
||
169 | |||
170 | /** |
||
171 | * {@inheritDoc} |
||
172 | */ |
||
173 | public function isDir(/*# string */ $path = '')/*# : bool */ |
||
181 | |||
182 | /** |
||
183 | * {@inheritDoc} |
||
184 | */ |
||
185 | public function rename(/*# string */ $destination)/*# : bool */ |
||
189 | |||
190 | /** |
||
191 | * {@inheritDoc} |
||
192 | */ |
||
193 | public function copy(/*# string */ $destination)/*# : bool */ |
||
197 | |||
198 | /** |
||
199 | * {@inheritDoc} |
||
200 | */ |
||
201 | View Code Duplication | public function delete()/*# : bool */ |
|
214 | |||
215 | /** |
||
216 | * Get the driver |
||
217 | * |
||
218 | * @return DriverInterface |
||
219 | * @access protected |
||
220 | */ |
||
221 | protected function getDriver()/*# : DriverInterface */ |
||
225 | |||
226 | /** |
||
227 | * Do copy or rename in same filesystem |
||
228 | * |
||
229 | * @param string $destination |
||
230 | * @param string $action 'copy' or 'rename' |
||
231 | * @return bool |
||
232 | * @access protected |
||
233 | */ |
||
234 | protected function alterAction( |
||
250 | |||
251 | /** |
||
252 | * Is current path has trailing '/' |
||
253 | * |
||
254 | * @param string $path |
||
255 | * @return bool |
||
256 | * @access protected |
||
257 | */ |
||
258 | protected function hasTrailingSlash(/*# string */ $path)/*# : bool */ |
||
266 | |||
267 | /** |
||
268 | * Reset error to driver's error |
||
269 | * |
||
270 | * @access protected |
||
271 | */ |
||
272 | protected function resetError() |
||
276 | } |
||
277 |