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 |
||
| 7 | class InMemoryFileSystem extends FileSystemAbstract |
||
| 8 | { |
||
| 9 | const DIR_DISCRIMINATOR = 'dir'; |
||
| 10 | const LINK_DISCRIMINATOR = 'link'; |
||
| 11 | const FILE_DISCRIMINATOR = 'file'; |
||
| 12 | |||
| 13 | const KEY_TYPE = 'type'; |
||
| 14 | const KEY_CONTENT = 'content'; |
||
| 15 | const KEY_CREATION_TIME = 'creation_time'; |
||
| 16 | |||
| 17 | /** @var array */ |
||
| 18 | private $fileSystem = []; |
||
| 19 | |||
| 20 | 30 | View Code Duplication | protected function dirExistsRaw(string $path): bool |
| 27 | |||
| 28 | 35 | View Code Duplication | protected function linkExistsRaw(string $path): bool |
| 35 | |||
| 36 | 38 | View Code Duplication | protected function fileExistsRaw(string $path): bool |
| 43 | |||
| 44 | 1 | protected function getFileCreationTimestampRaw(string $path): int |
|
| 48 | |||
| 49 | 10 | protected function readFileRaw(string $path): string |
|
| 53 | |||
| 54 | 7 | protected function writeFileRaw(string $path, string $content) |
|
| 62 | |||
| 63 | 4 | protected function copyFileRaw(string $sourcePath, string $destinationPath) |
|
| 67 | |||
| 68 | 2 | protected function deleteFileRaw(string $path) |
|
| 72 | |||
| 73 | 3 | protected function createLinkRaw(string $path, string $targetPath) |
|
| 80 | |||
| 81 | 7 | protected function getLinkTargetRaw(string $path): string |
|
| 85 | |||
| 86 | 5 | protected function createDirRaw(string $path) |
|
| 92 | |||
| 93 | 3 | protected function deleteDirRaw(string $path) |
|
| 101 | |||
| 102 | /** |
||
| 103 | * @return string[] The array with the file and dir names |
||
| 104 | */ |
||
| 105 | 5 | protected function readDirRaw(string $path): array |
|
| 126 | } |
||
| 127 |