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 Copycom implements Simulator |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * API access key |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $appKey; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * API access token |
||
| 33 | * |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | protected $appSecret; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * API access key |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $userKey; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * API access token |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $userSecret; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Remote path |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $path; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * (non-PHPDoc) |
||
| 61 | * |
||
| 62 | * @see \phpbu\App\Backup\Sync::setup() |
||
| 63 | * @param array $config |
||
| 64 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 65 | */ |
||
| 66 | 6 | View Code Duplication | public function setup(array $config) |
| 92 | |||
| 93 | /** |
||
| 94 | * (non-PHPDoc) |
||
| 95 | * |
||
| 96 | * @see \phpbu\App\Backup\Sync::sync() |
||
| 97 | * @param \phpbu\App\Backup\Target $target |
||
| 98 | * @param \phpbu\App\Result $result |
||
| 99 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 100 | */ |
||
| 101 | public function sync(Target $target, Result $result) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Simulate the sync execution. |
||
| 128 | * |
||
| 129 | * @param \phpbu\App\Backup\Target $target |
||
| 130 | * @param \phpbu\App\Result $result |
||
| 131 | */ |
||
| 132 | public function simulate(Target $target, Result $result) |
||
| 143 | } |
||
| 144 |