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