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 |
||
25 | class Simulate extends Compression |
||
26 | { |
||
27 | /** |
||
28 | * Execute backups. |
||
29 | * |
||
30 | * @param \phpbu\App\Configuration $configuration |
||
31 | * @return \phpbu\App\Result |
||
32 | * @throws \Exception |
||
33 | */ |
||
34 | 5 | public function run(Configuration $configuration) : Result |
|
61 | |||
62 | /** |
||
63 | * Simulate the backup. |
||
64 | * |
||
65 | * @param \phpbu\App\Configuration\Backup $conf |
||
66 | * @param \phpbu\App\Backup\Target $target |
||
67 | * @throws \Exception |
||
68 | */ |
||
69 | 5 | View Code Duplication | protected function simulateSource(Configuration\Backup $conf, Target $target) |
81 | |||
82 | /** |
||
83 | * Simulate checks. |
||
84 | * |
||
85 | * @param \phpbu\App\Configuration\Backup $backup |
||
86 | * @param \phpbu\App\Backup\Target $target |
||
87 | * @param \phpbu\App\Backup\Collector $collector |
||
88 | * @throws \Exception |
||
89 | */ |
||
90 | 5 | View Code Duplication | protected function simulateChecks(Configuration\Backup $backup, Target $target, Collector $collector) |
101 | |||
102 | /** |
||
103 | * Simulate encryption. |
||
104 | * |
||
105 | * @param \phpbu\App\Configuration\Backup $backup |
||
106 | * @param \phpbu\App\Backup\Target $target |
||
107 | * @throws \phpbu\App\Exception |
||
108 | */ |
||
109 | 5 | View Code Duplication | protected function simulateCrypt(Configuration\Backup $backup, Target $target) |
121 | |||
122 | /** |
||
123 | * Simulate all syncs. |
||
124 | * |
||
125 | * @param \phpbu\App\Configuration\Backup $backup |
||
126 | * @param \phpbu\App\Backup\Target $target |
||
127 | * @throws \Exception |
||
128 | */ |
||
129 | 5 | protected function simulateSyncs(Configuration\Backup $backup, Target $target) |
|
139 | |||
140 | /** |
||
141 | * Simulate the cleanup. |
||
142 | * |
||
143 | * @param \phpbu\App\Configuration\Backup $backup |
||
144 | * @param \phpbu\App\Backup\Target $target |
||
145 | * @param \phpbu\App\Backup\Collector $collector |
||
146 | * @throws \phpbu\App\Exception |
||
147 | */ |
||
148 | 5 | View Code Duplication | protected function simulateCleanup(Configuration\Backup $backup, Target $target, Collector $collector) |
161 | |||
162 | /** |
||
163 | * Execute the compressor. |
||
164 | * Returns the path to the created archive file. |
||
165 | * |
||
166 | * @param \phpbu\App\Backup\Compressor\Executable $compressor |
||
167 | * @param \phpbu\App\Backup\Target $target |
||
168 | * @param \phpbu\App\Result $result |
||
169 | * @return string |
||
170 | */ |
||
171 | 3 | protected function executeCompressor(Compressor\Executable $compressor, Target $target, Result $result) : string |
|
176 | } |
||
177 |