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 |
||
| 26 | class Filesystem extends \Symfony\Component\Filesystem\Filesystem |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * Build an absolute file or directory path separated by the OS specific directory separator |
||
| 30 | * |
||
| 31 | * @param string ...$pathFragments |
||
| 32 | * |
||
| 33 | * @return string |
||
| 34 | */ |
||
| 35 | 3 | public function absolutePath ($pathFragments) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * Build a file or directory path separated by the OS specific directory separator |
||
| 50 | * |
||
| 51 | * @param string ...$pathFragments |
||
| 52 | * |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | 6 | public function appendPath ($pathFragments) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Copy a file or folder recursively |
||
| 62 | * |
||
| 63 | * @param string $originFile The original filename |
||
| 64 | * @param string $targetFile The target filename |
||
| 65 | * @param bool $overwriteNewerFiles If true, target files newer than origin files are overwritten |
||
| 66 | * |
||
| 67 | * @throws FileNotFoundException When originFile doesn't exist |
||
| 68 | * @throws IOException When copy fails |
||
| 69 | */ |
||
| 70 | public function copy($originFile, $targetFile, $overwriteNewerFiles = false) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Strip the current working directory from an absolute path |
||
| 99 | * |
||
| 100 | * @param string $path An absolute path |
||
| 101 | * |
||
| 102 | * @return string |
||
| 103 | */ |
||
| 104 | public function getRelativePath ($path) |
||
| 108 | |||
| 109 | 3 | public function getFinder ($explicitIncludes = array(), $explicitIgnores = array(), $searchIn = "") |
|
| 147 | |||
| 148 | /** |
||
| 149 | * Get the name of a given file without the extension |
||
| 150 | * |
||
| 151 | * @param string $filePath A file path |
||
| 152 | * |
||
| 153 | * @return string |
||
| 154 | */ |
||
| 155 | 6 | public function getBaseName ($filePath) |
|
| 159 | |||
| 160 | /** |
||
| 161 | * Get the name of a given file |
||
| 162 | * |
||
| 163 | * @param string $filePath A file path |
||
| 164 | * |
||
| 165 | * @return string |
||
| 166 | */ |
||
| 167 | 2 | public function getFileName ($filePath) |
|
| 171 | |||
| 172 | /** |
||
| 173 | * Get the parent directory of a given file |
||
| 174 | * |
||
| 175 | * @param string $filePath A file path |
||
| 176 | * |
||
| 177 | * @return string |
||
| 178 | */ |
||
| 179 | 3 | public function getFolderPath ($filePath) |
|
| 183 | |||
| 184 | /** |
||
| 185 | * Get the extension of a given file |
||
| 186 | * |
||
| 187 | * @param string $filename A file path |
||
| 188 | * |
||
| 189 | * @return string The extension of the file |
||
| 190 | */ |
||
| 191 | 26 | public function getExtension ($filename) |
|
| 195 | |||
| 196 | /** |
||
| 197 | * @param string $folderPath |
||
| 198 | */ |
||
| 199 | public function isDir ($folderPath) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Get the full path to the file without the extension |
||
| 206 | * |
||
| 207 | * @param string $filename A file path |
||
| 208 | * |
||
| 209 | * @return string |
||
| 210 | */ |
||
| 211 | 3 | public function removeExtension ($filename) |
|
| 218 | |||
| 219 | /** |
||
| 220 | * Write a file |
||
| 221 | * |
||
| 222 | * @param string $targetDir The directory of where the file will be created; the file name is a separate variable |
||
| 223 | * @param string $fileName The name of the file |
||
| 224 | * @param string $content The content that belongs in the file |
||
| 225 | * |
||
| 226 | * @return SplFileInfo A reference to the newly created file |
||
| 227 | */ |
||
| 228 | View Code Duplication | public function writeFile ($targetDir, $fileName, $content) |
|
| 246 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.