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 RackspaceAdapterFactory extends AbstractAdapterFactory |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @inheritdoc |
||
| 15 | */ |
||
| 16 | 1 | public function doCreateService(ServiceLocatorInterface $serviceLocator) |
|
| 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 | 1 | $proxy = $this->getLazyFactory($serviceLocator)->createProxy( |
|
| 28 | 1 | \League\Flysystem\Rackspace\RackspaceAdapter::class, |
|
| 29 | 1 | function (&$wrappedObject, $proxy, $method, $parameters, &$initializer) { |
|
| 30 | $client = new OpenStack( |
||
| 31 | $this->options['url'], |
||
| 32 | $this->options['secret'], |
||
| 33 | $this->options['options'] |
||
| 34 | ); |
||
| 35 | |||
| 36 | $store = $client->objectStoreService( |
||
| 37 | $this->options['objectstore']['name'], |
||
| 38 | $this->options['objectstore']['region'], |
||
| 39 | $this->options['objectstore']['url_type'] |
||
| 40 | ); |
||
| 41 | |||
| 42 | $container = $store->getContainer($this->options['objectstore']['container']); |
||
| 43 | |||
| 44 | $wrappedObject = new Adapter($container, $this->options['prefix']); |
||
| 45 | |||
| 46 | return true; |
||
| 47 | 1 | } |
|
| 48 | ); |
||
| 49 | |||
| 50 | 1 | return $proxy; |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @inheritdoc |
||
| 55 | */ |
||
| 56 | 10 | protected function validateConfig() |
|
| 88 | } |
||
| 89 |