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 |
||
22 | class Local extends Abstraction implements Collector |
||
23 | { |
||
24 | /** |
||
25 | * Constructor |
||
26 | * |
||
27 | * @param \phpbu\App\Backup\Target $target |
||
28 | */ |
||
29 | public function __construct(Target $target) |
||
34 | |||
35 | /** |
||
36 | * Collect all created backups. |
||
37 | */ |
||
38 | protected function collectBackups() |
||
42 | |||
43 | /** |
||
44 | * Recursive backup collecting. |
||
45 | * |
||
46 | * @param string $path |
||
47 | */ |
||
48 | protected function collect(string $path) |
||
66 | |||
67 | 10 | /** |
|
68 | * Collect backup files in directory. |
||
69 | 10 | * |
|
70 | * @param \DirectoryIterator $dirIterator |
||
71 | */ |
||
72 | protected function collectFiles(DirectoryIterator $dirIterator) |
||
86 | |||
87 | 6 | /** |
|
88 | 6 | * Check if the iterated file is part of a valid target path. |
|
89 | * |
||
90 | * @param \SplFileInfo $file |
||
91 | * @param int $depth |
||
92 | 10 | * @return bool |
|
93 | */ |
||
94 | 10 | protected function isValidDirectory(SplFileInfo $file, int $depth) |
|
98 | |||
99 | /** |
||
100 | * Does a directory match the respective target path. |
||
101 | 10 | * |
|
102 | * @param string $dir |
||
103 | 10 | * @param int $depth |
|
104 | 10 | * @return bool |
|
105 | 10 | */ |
|
106 | protected function isMatchingDirectory(string $dir, int $depth) |
||
112 | } |
||
113 |