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 RackspaceAdapterFactory extends AbstractAdapterFactory |
||
| 15 | { |
||
| 16 | 1 | public function doCreateService(ServiceLocatorInterface $serviceLocator): AdapterInterface |
|
| 17 | { |
||
| 18 | 1 | if (! class_exists(\League\Flysystem\Rackspace\RackspaceAdapter::class) || |
|
| 19 | 1 | ! class_exists(\ProxyManager\Factory\LazyLoadingValueHolderFactory::class) |
|
| 20 | ) { |
||
| 21 | throw new RequirementsException( |
||
| 22 | ['league/flysystem-rackspace', 'ocramius/proxy-manager'], |
||
| 23 | 'Rackspace' |
||
| 24 | ); |
||
| 25 | } |
||
| 26 | |||
| 27 | /** @var AdapterInterface $proxy */ |
||
| 28 | 1 | $proxy = $this->getLazyFactory($serviceLocator)->createProxy( |
|
| 29 | 1 | \League\Flysystem\Rackspace\RackspaceAdapter::class, |
|
| 30 | 1 | function (&$wrappedObject, $proxy, $method, $parameters, &$initializer) { |
|
| 31 | $client = new OpenStack( |
||
| 32 | $this->options['url'], |
||
| 33 | $this->options['secret'], |
||
| 34 | $this->options['options'] |
||
| 35 | ); |
||
| 36 | |||
| 37 | $store = $client->objectStoreService( |
||
| 38 | $this->options['objectstore']['name'], |
||
| 39 | $this->options['objectstore']['region'], |
||
| 40 | $this->options['objectstore']['url_type'] |
||
| 41 | ); |
||
| 42 | |||
| 43 | $container = $store->getContainer($this->options['objectstore']['container']); |
||
| 44 | |||
| 45 | $wrappedObject = new Adapter($container, $this->options['prefix']); |
||
| 46 | |||
| 47 | return true; |
||
| 48 | 1 | } |
|
| 49 | ); |
||
| 50 | |||
| 51 | 1 | return $proxy; |
|
| 52 | } |
||
| 53 | |||
| 54 | 10 | protected function validateConfig() |
|
| 86 | } |
||
| 87 |