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 | View Code Duplication | class DropboxAdapterFactory extends AbstractAdapterFactory |
|
| 12 | { |
||
| 13 | /** |
||
| 14 | * @inheritdoc |
||
| 15 | */ |
||
| 16 | public function doCreateService(ServiceLocatorInterface $serviceLocator) |
||
| 17 | { |
||
| 18 | if (!class_exists(\Spatie\FlysystemDropbox\DropboxAdapter::class)) { |
||
| 19 | throw new RequirementsException( |
||
| 20 | ['spatie/flysystem-dropbox'], |
||
| 21 | 'Dropbox' |
||
| 22 | ); |
||
| 23 | } |
||
| 24 | |||
| 25 | $client = new \Spatie\Dropbox\Client( |
||
| 26 | $this->options['access_token'] |
||
| 27 | ); |
||
| 28 | |||
| 29 | $adapter = new Adapter($client, $this->options['prefix']); |
||
| 30 | |||
| 31 | return $adapter; |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @inheritdoc |
||
| 36 | */ |
||
| 37 | 2 | protected function validateConfig() |
|
| 47 | } |
||
| 48 |