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 |
||
20 | class Laravel implements BasicIface, DirIface, MetaIface |
||
21 | { |
||
22 | private $fs; |
||
23 | |||
24 | |||
25 | /** |
||
26 | * Initializes the object |
||
27 | * |
||
28 | * @param string $basepath Root path to the file system |
||
|
|||
29 | */ |
||
30 | public function __construct( \Illuminate\Contracts\Filesystem\Filesystem $fs ) |
||
34 | |||
35 | |||
36 | /** |
||
37 | * Tests if the given path is a directory |
||
38 | * |
||
39 | * @param string $path Path to the file or directory |
||
40 | * @return boolean True if directory, false if not |
||
41 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
42 | */ |
||
43 | public function isdir( $path ) |
||
47 | |||
48 | |||
49 | /** |
||
50 | * Creates a new directory for the given path |
||
51 | * |
||
52 | * @param string $path Path to the directory |
||
53 | * @return void |
||
54 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
55 | */ |
||
56 | public function mkdir( $path ) |
||
64 | |||
65 | |||
66 | /** |
||
67 | * Deletes the directory for the given path |
||
68 | * |
||
69 | * @param string $path Path to the directory |
||
70 | * @return void |
||
71 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
72 | */ |
||
73 | public function rmdir( $path ) |
||
81 | |||
82 | |||
83 | /** |
||
84 | * Returns an iterator over the entries in the given path |
||
85 | * |
||
86 | * {@inheritDoc} |
||
87 | * |
||
88 | * @param string $path Path to the filesystem or directory |
||
89 | * @return \Iterator|array Iterator over the entries or array with entries |
||
90 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
91 | */ |
||
92 | public function scan( $path = null ) |
||
100 | |||
101 | |||
102 | /** |
||
103 | * Returns the file size |
||
104 | * |
||
105 | * @param string $path Path to the file |
||
106 | * @return integer Size in bytes |
||
107 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
108 | */ |
||
109 | public function size( $path ) |
||
117 | |||
118 | |||
119 | /** |
||
120 | * Returns the Unix time stamp for the file |
||
121 | * |
||
122 | * @param string $path Path to the file |
||
123 | * @return integer Unix time stamp in seconds |
||
124 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
125 | */ |
||
126 | public function time( $path ) |
||
134 | |||
135 | |||
136 | /** |
||
137 | * Deletes the file for the given path |
||
138 | * |
||
139 | * @param string $path Path to the file |
||
140 | * @return void |
||
141 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
142 | */ |
||
143 | public function rm( $path ) |
||
151 | |||
152 | |||
153 | /** |
||
154 | * Tests if a file exists at the given path |
||
155 | * |
||
156 | * @param string $path Path to the file |
||
157 | * @return boolean True if it exists, false if not |
||
158 | */ |
||
159 | public function has( $path ) |
||
163 | |||
164 | |||
165 | /** |
||
166 | * Returns the content of the file |
||
167 | * |
||
168 | * {@inheritDoc} |
||
169 | * |
||
170 | * @param string $path Path to the file |
||
171 | * @return string File content |
||
172 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
173 | */ |
||
174 | public function read( $path ) |
||
182 | |||
183 | |||
184 | /** |
||
185 | * Returns the stream descriptor for the file |
||
186 | * |
||
187 | * {@inheritDoc} |
||
188 | * |
||
189 | * @param string $path Path to the file |
||
190 | * @return resource File stream descriptor |
||
191 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
192 | */ |
||
193 | public function reads( $path ) |
||
218 | |||
219 | |||
220 | /** |
||
221 | * Writes the given content to the file |
||
222 | * |
||
223 | * {@inheritDoc} |
||
224 | * |
||
225 | * @param string $path Path to the file |
||
226 | * @param string $content New file content |
||
227 | * @return void |
||
228 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
229 | */ |
||
230 | public function write( $path, $content ) |
||
238 | |||
239 | |||
240 | /** |
||
241 | * Write the content of the stream descriptor into the remote file |
||
242 | * |
||
243 | * {@inheritDoc} |
||
244 | * |
||
245 | * @param string $path Path to the file |
||
246 | * @param resource $stream File stream descriptor |
||
247 | * @return void |
||
248 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
249 | */ |
||
250 | public function writes( $path, $stream ) |
||
263 | |||
264 | |||
265 | /** |
||
266 | * Renames a file, moves it to a new location or both at once |
||
267 | * |
||
268 | * @param string $from Path to the original file |
||
269 | * @param string $to Path to the new file |
||
270 | * @return void |
||
271 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
272 | */ |
||
273 | public function move( $from, $to ) |
||
281 | |||
282 | |||
283 | /** |
||
284 | * Copies a file to a new location |
||
285 | * |
||
286 | * @param string $from Path to the original file |
||
287 | * @param string $to Path to the new file |
||
288 | * @return void |
||
289 | * @throws \Aimeos\MW\Filesystem\Exception If an error occurs |
||
290 | */ |
||
291 | public function copy( $from, $to ) |
||
299 | } |
||
300 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.