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 Capacity extends Abstraction implements Simulator |
||
26 | { |
||
27 | /** |
||
28 | * Original XML value |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $capacityRaw; |
||
33 | |||
34 | /** |
||
35 | * Capacity in bytes. |
||
36 | * |
||
37 | * @var mixed <integer|double> |
||
38 | */ |
||
39 | protected $capacityBytes; |
||
40 | |||
41 | /** |
||
42 | * Setup the the Cleaner. |
||
43 | * |
||
44 | * @see \phpbu\App\Backup\Cleanup::setup() |
||
45 | * @param array $options |
||
46 | * @throws \phpbu\App\Backup\Cleaner\Exception |
||
47 | */ |
||
48 | View Code Duplication | public function setup(array $options) |
|
61 | 1 | ||
62 | 1 | /** |
|
63 | * Return list of files to delete. |
||
64 | 7 | * |
|
65 | 7 | * @param \phpbu\App\Backup\Target $target |
|
66 | 7 | * @param \phpbu\App\Backup\Collector $collector |
|
67 | 7 | * @return \phpbu\App\Backup\File\Local[] |
|
68 | * @throws \phpbu\App\Exception |
||
69 | */ |
||
70 | protected function getFilesToDelete(Target $target, Collector $collector) |
||
99 | |||
100 | 6 | /** |
|
101 | * Is a given size bigger than the configured capacity limit. |
||
102 | 6 | * |
|
103 | 6 | * @param int|double $currentCapacity |
|
104 | 6 | * @return bool |
|
105 | */ |
||
106 | protected function isCapacityExceeded($currentCapacity): bool |
||
110 | } |
||
111 |