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 |
||
| 20 | abstract class AmazonS3 implements Simulator |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * AWS key |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $key; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * AWS secret |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $secret; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * AWS S3 bucket |
||
| 38 | * |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | protected $bucket; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * TTL for all items in this bucket. |
||
| 45 | * |
||
| 46 | * @var int |
||
| 47 | */ |
||
| 48 | protected $bucketTTL; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * AWS S3 region |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | protected $region; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * AWS remote path / object key |
||
| 59 | * |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | protected $path; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * AWS acl |
||
| 66 | * 'private' by default |
||
| 67 | * |
||
| 68 | * @var string |
||
| 69 | */ |
||
| 70 | protected $acl; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Use multi part config |
||
| 74 | 6 | * |
|
| 75 | * @var boolean |
||
| 76 | 6 | */ |
|
| 77 | protected $multiPartUpload; |
||
| 78 | |||
| 79 | 6 | /** |
|
| 80 | 1 | * Min multi part upload size |
|
| 81 | * |
||
| 82 | 5 | * @var int |
|
| 83 | 1 | */ |
|
| 84 | protected $minMultiPartUploadSize = 5242880; |
||
| 85 | 4 | ||
| 86 | 1 | /** |
|
| 87 | * Max stream upload size |
||
| 88 | 3 | * |
|
| 89 | 1 | * @var int |
|
| 90 | */ |
||
| 91 | 2 | protected $maxStreamUploadSize = 104857600; |
|
| 92 | 1 | ||
| 93 | /** |
||
| 94 | 1 | * Configure the sync. |
|
| 95 | 1 | * |
|
| 96 | 1 | * @see \phpbu\App\Backup\Sync::setup() |
|
| 97 | 1 | * @param array $config |
|
| 98 | 1 | * @throws \phpbu\App\Backup\Sync\Exception |
|
| 99 | 1 | */ |
|
| 100 | 1 | public function setup(array $config) |
|
| 118 | |||
| 119 | /** |
||
| 120 | * Make sure all mandatory keys are present in given config. |
||
| 121 | * |
||
| 122 | * @param array $config |
||
| 123 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 124 | */ |
||
| 125 | protected function validateConfig(array $config) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Execute the sync |
||
| 136 | * |
||
| 137 | * @see \phpbu\App\Backup\Sync::sync() |
||
| 138 | * @param \phpbu\App\Backup\Target $target |
||
| 139 | * @param \phpbu\App\Result $result |
||
| 140 | * @throws \phpbu\App\Backup\Sync\Exception |
||
| 141 | */ |
||
| 142 | abstract public function sync(Target $target, Result $result); |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Simulate the sync execution. |
||
| 146 | * |
||
| 147 | * @param \phpbu\App\Backup\Target $target |
||
| 148 | * @param \phpbu\App\Result $result |
||
| 149 | */ |
||
| 150 | public function simulate(Target $target, Result $result) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Should multi part upload be used. |
||
| 163 | * |
||
| 164 | * @param \phpbu\App\Backup\Target $target |
||
| 165 | * @return bool |
||
| 166 | */ |
||
| 167 | protected function useMultiPartUpload(Target $target) |
||
| 175 | } |
||
| 176 |