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 SoftLayer implements Simulator |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * SoftLayer user |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $user; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * SoftLayer secret |
||
| 36 | * |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | protected $secret; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * SoftLayer container |
||
| 43 | * |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | protected $container; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * SoftLayer host |
||
| 50 | * |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | protected $host; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * SoftLayer remote path |
||
| 57 | * |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | protected $path; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * (non-PHPDoc) |
||
| 64 | * |
||
| 65 | * @see \phpbu\App\Backup\Sync::setup() |
||
| 66 | * @param array $config |
||
| 67 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 68 | */ |
||
| 69 | 7 | public function setup(array $config) |
|
| 89 | |||
| 90 | /** |
||
| 91 | * (non-PHPDoc) |
||
| 92 | * |
||
| 93 | * @see \phpbu\App\Backup\Sync::sync() |
||
| 94 | * @param \phpbu\App\backup\Target $target |
||
| 95 | * @param \phpbu\App\Result $result |
||
| 96 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 97 | */ |
||
| 98 | public function sync(Target $target, Result $result) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Simulate the sync execution. |
||
| 125 | * |
||
| 126 | * @param \phpbu\App\Backup\Target $target |
||
| 127 | * @param \phpbu\App\Result $result |
||
| 128 | */ |
||
| 129 | 1 | public function simulate(Target $target, Result $result) |
|
| 140 | |||
| 141 | /** |
||
| 142 | * Execute the remote clean up if needed |
||
| 143 | * |
||
| 144 | * @param \phpbu\App\Backup\Target $target |
||
| 145 | * @param \phpbu\App\Result $result |
||
| 146 | */ |
||
| 147 | public function cleanup(Target $target, Result $result) |
||
| 151 | } |
||
| 152 |