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 |
||
| 14 | class AwsS3v3AdapterFactory extends AbstractAdapterFactory |
||
| 15 | { |
||
| 16 | public function doCreateService(ServiceLocatorInterface $serviceLocator): AdapterInterface |
||
| 17 | { |
||
| 18 | if (! class_exists(\League\Flysystem\AwsS3v3\AwsS3Adapter::class)) { |
||
| 19 | throw new RequirementsException( |
||
| 20 | ['league/flysystem-aws-s3-v3'], |
||
| 21 | 'AwsS3v3' |
||
| 22 | ); |
||
| 23 | } |
||
| 24 | $config = [ |
||
| 25 | 'region' => $this->options['region'], |
||
| 26 | 'version' => $this->options['version'], |
||
| 27 | 'request.options' => $this->options['request.options'], |
||
| 28 | ]; |
||
| 29 | |||
| 30 | if (! isset($this->options['iam']) || (isset($this->options['iam']) && (false === $this->options['iam']))) { |
||
| 31 | $credentials = [ |
||
| 32 | 'key' => $this->options['credentials']['key'], |
||
| 33 | 'secret' => $this->options['credentials']['secret'], |
||
| 34 | ]; |
||
| 35 | $config = array_merge(compact('credentials'), $config); |
||
| 36 | } |
||
| 37 | |||
| 38 | $client = new S3Client($config); |
||
| 39 | |||
| 40 | $adapter = new Adapter($client, $this->options['bucket'], $this->options['prefix']); |
||
| 41 | |||
| 42 | return $adapter; |
||
| 43 | } |
||
| 44 | |||
| 45 | 9 | protected function validateConfig() |
|
| 81 | } |
||
| 82 |