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 | class AmazonS3v3 extends AmazonS3 |
||
21 | { |
||
22 | use Clearable; |
||
23 | |||
24 | /** |
||
25 | * Amazon S3 client. |
||
26 | * |
||
27 | * @var S3Client; |
||
28 | */ |
||
29 | protected $client; |
||
30 | |||
31 | /** |
||
32 | * Configure the sync. |
||
33 | * |
||
34 | * @see \phpbu\App\Backup\Sync::setup() |
||
35 | * @param array $config |
||
36 | * @throws \phpbu\App\Backup\Sync\Exception |
||
37 | * @throws \phpbu\App\Exception |
||
38 | */ |
||
39 | 9 | public function setup(array $config) |
|
45 | |||
46 | /** |
||
47 | * Execute the sync. |
||
48 | * |
||
49 | * @see \phpbu\App\Backup\Sync::sync() |
||
50 | * @param \phpbu\App\Backup\Target $target |
||
51 | * @param \phpbu\App\Result $result |
||
52 | * @throws \phpbu\App\Backup\Sync\Exception |
||
53 | */ |
||
54 | public function sync(Target $target, Result $result) |
||
79 | |||
80 | /** |
||
81 | * Execute the remote clean up if needed |
||
82 | * |
||
83 | * @param \phpbu\App\Backup\Target $target |
||
84 | * @param \phpbu\App\Result $result |
||
85 | */ |
||
86 | View Code Duplication | public function cleanup(Target $target, Result $result) |
|
95 | |||
96 | /** |
||
97 | * Simulate the sync execution. |
||
98 | * |
||
99 | * @param \phpbu\App\Backup\Target $target |
||
100 | * @param \phpbu\App\Result $result |
||
101 | */ |
||
102 | 1 | public function simulate(Target $target, Result $result) |
|
108 | |||
109 | /** |
||
110 | * Create a s3 bucket. |
||
111 | * |
||
112 | * @param \Aws\S3\S3Client $s3 |
||
113 | */ |
||
114 | private function createBucket(S3Client $s3) |
||
124 | |||
125 | /** |
||
126 | * Upload backup to Amazon S3 bucket. |
||
127 | * |
||
128 | * @param \phpbu\App\Backup\Target $target |
||
129 | * @param \Aws\S3\S3Client $s3 |
||
130 | */ |
||
131 | private function upload(Target $target, S3Client $s3) |
||
139 | |||
140 | /** |
||
141 | * Upload via stream wrapper. |
||
142 | * |
||
143 | * @param \phpbu\App\Backup\Target $target |
||
144 | * @param \Aws\S3\S3Client $s3 |
||
145 | * @throws \phpbu\App\Backup\Sync\Exception |
||
146 | */ |
||
147 | private function uploadStream(Target $target, S3Client $s3) |
||
157 | |||
158 | /** |
||
159 | * Upload via multi part. |
||
160 | * |
||
161 | * @param \phpbu\App\Backup\Target $target |
||
162 | * @param \Aws\S3\S3Client $s3 |
||
163 | * @param \Aws\Exception\MultipartUploadException |
||
164 | */ |
||
165 | private function uploadMultiPart(Target $target, S3Client $s3) |
||
173 | |||
174 | /** |
||
175 | * Open stream and validate it. |
||
176 | * |
||
177 | * @param string $path |
||
178 | * @param string $mode |
||
179 | * @return resource |
||
180 | * @throws \phpbu\App\Backup\Sync\Exception |
||
181 | */ |
||
182 | private function getFileHandle($path, $mode) |
||
190 | |||
191 | /** |
||
192 | * Get the s3 upload path |
||
193 | * |
||
194 | * @param \phpbu\App\Backup\Target $target |
||
195 | * @return string |
||
196 | */ |
||
197 | 2 | public function getUploadPath(Target $target) |
|
204 | } |
||
205 |