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 |
||
| 12 | class CopyAdapterFactory extends AbstractAdapterFactory |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @inheritdoc |
||
| 16 | */ |
||
| 17 | 1 | View Code Duplication | public function doCreateService(ServiceLocatorInterface $serviceLocator) |
| 18 | { |
||
| 19 | if (!class_exists(\League\Flysystem\Copy\CopyAdapter::class)) { |
||
| 20 | throw new RequirementsException( |
||
| 21 | ['league/flysystem-copy'], |
||
| 22 | 'Copy' |
||
| 23 | ); |
||
| 24 | } |
||
| 25 | |||
| 26 | 1 | $client = new API( |
|
| 27 | 1 | $this->options['consumer_key'], |
|
| 28 | 1 | $this->options['consumer_secret'], |
|
| 29 | 1 | $this->options['access_token'], |
|
| 30 | 1 | $this->options['token_secret'] |
|
| 31 | ); |
||
| 32 | |||
| 33 | 1 | $adapter = new Adapter($client, $this->options['prefix']); |
|
| 34 | |||
| 35 | 1 | return $adapter; |
|
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @inheritdoc |
||
| 40 | */ |
||
| 41 | protected function validateConfig() |
||
| 63 | } |
||
| 64 |