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 |
||
23 | class AmazonS3v3 extends Remote implements Collector |
||
24 | { |
||
25 | /** |
||
26 | * @var \Aws\S3\S3Client |
||
27 | */ |
||
28 | protected $client; |
||
29 | |||
30 | /** |
||
31 | * Amazon S3 bucket name |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $bucket; |
||
36 | |||
37 | /** |
||
38 | * Amazon S3 constructor. |
||
39 | * |
||
40 | * @param \phpbu\App\Backup\Target $target |
||
41 | * @param \phpbu\App\Backup\Path $path |
||
42 | * @param \Aws\S3\S3Client $client |
||
43 | * @param string $bucket |
||
44 | */ |
||
45 | public function __construct(Target $target, Path $path, S3Client $client, string $bucket) |
||
51 | 1 | ||
52 | 1 | /** |
|
53 | * Collect all created backups. |
||
54 | */ |
||
55 | protected function collectBackups() |
||
74 | |||
75 | 1 | /** |
|
76 | 1 | * Return prefix for querying remote files and folders |
|
77 | 1 | * |
|
78 | * @param string $path |
||
79 | * @return string |
||
80 | */ |
||
81 | 1 | protected function getPrefix($path): string |
|
87 | } |
||
88 |