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 |
||
| 15 | final class FileSystemAdapter implements LockFileSystemInterface |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var FileSystemInterface |
||
| 19 | */ |
||
| 20 | private $fileSystem; |
||
| 21 | |||
| 22 | 22 | public function __construct(FileSystemInterface $fileSystem = null) |
|
| 26 | |||
| 27 | /** |
||
| 28 | * @throws LockInvalidPathException |
||
| 29 | */ |
||
| 30 | 11 | public function fileExists(string $path): bool |
|
| 38 | |||
| 39 | /** |
||
| 40 | * @throws LockInvalidPathException |
||
| 41 | */ |
||
| 42 | 4 | public function deleteFile(string $path): bool |
|
| 50 | |||
| 51 | /** |
||
| 52 | * Creates a folder and all intermediate folders if they don't exist |
||
| 53 | * |
||
| 54 | * @throws LockInvalidPathException |
||
| 55 | * @throws LockPathAlreadyExistsException |
||
| 56 | */ |
||
| 57 | 8 | View Code Duplication | public function createDir(string $path): bool |
| 67 | |||
| 68 | /** |
||
| 69 | * @throws LockFileNotFoundException |
||
| 70 | * @throws LockInvalidPathException |
||
| 71 | */ |
||
| 72 | 9 | public function readFile(string $path): string |
|
| 82 | |||
| 83 | /** |
||
| 84 | * @throws LockPathAlreadyExistsException |
||
| 85 | * @throws LockInvalidPathException |
||
| 86 | */ |
||
| 87 | 8 | View Code Duplication | public function writeFile(string $path, string $content) |
| 97 | } |
||
| 98 |