| Conditions | 12 |
| Paths | 30 |
| Total Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 26 | public function process(ContainerBuilder $container) |
||
| 27 | { |
||
| 28 | if (!$container->hasDefinition('ezpublish.persistence.external_storage_registry.factory')) { |
||
| 29 | return; |
||
| 30 | } |
||
| 31 | |||
| 32 | $externalStorageRegistryFactoryDefinition = $container->getDefinition( |
||
| 33 | 'ezpublish.persistence.external_storage_registry.factory' |
||
| 34 | ); |
||
| 35 | |||
| 36 | // Gateways for external storage handlers. |
||
| 37 | // Alias attribute is the corresponding field type string. |
||
| 38 | $externalStorageGateways = []; |
||
| 39 | // Referencing the services by alias (field type string) |
||
| 40 | foreach ($container->findTaggedServiceIds('ezpublish.fieldType.externalStorageHandler.gateway') as $id => $attributes) { |
||
| 41 | foreach ($attributes as $attribute) { |
||
| 42 | if (!isset($attribute['alias'])) { |
||
| 43 | throw new LogicException('ezpublish.fieldType.externalStorageHandler.gateway service tag needs an "alias" attribute to identify the field type. None given.'); |
||
| 44 | } |
||
| 45 | |||
| 46 | if (!isset($attribute['identifier'])) { |
||
| 47 | throw new LogicException('ezpublish.fieldType.externalStorageHandler.gateway service tag needs an "identifier" attribute to identify the gateway. None given.'); |
||
| 48 | } |
||
| 49 | |||
| 50 | $externalStorageGateways[$attribute['alias']] = [ |
||
| 51 | 'id' => $id, |
||
| 52 | 'identifier' => $attribute['identifier'], |
||
| 53 | ]; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | // External storage handlers for field types that need them. |
||
| 58 | // Alias attribute is the field type string. |
||
| 59 | foreach ($container->findTaggedServiceIds('ezpublish.fieldType.externalStorageHandler') as $id => $attributes) { |
||
| 60 | foreach ($attributes as $attribute) { |
||
| 61 | if (!isset($attribute['alias'])) { |
||
| 62 | throw new LogicException('ezpublish.fieldType.externalStorageHandler service tag needs an "alias" attribute to identify the field type. None given.'); |
||
| 63 | } |
||
| 64 | |||
| 65 | // If the storage handler is gateway based, then we need to add a corresponding gateway to it. |
||
| 66 | // Will throw a LogicException if no gateway is defined for this field type. |
||
| 67 | $storageHandlerDef = $container->findDefinition($id); |
||
| 68 | $storageHandlerClass = $storageHandlerDef->getClass(); |
||
| 69 | if (preg_match('/^%([^%\s]+)%$/', $storageHandlerClass, $match)) { |
||
| 70 | $storageHandlerClass = $container->getParameter($match[1]); |
||
| 71 | } |
||
| 72 | |||
| 73 | if ( |
||
| 74 | is_subclass_of( |
||
| 75 | $storageHandlerClass, |
||
| 76 | 'eZ\\Publish\\Core\\FieldType\\GatewayBasedStorage' |
||
| 77 | ) |
||
| 78 | ) { |
||
| 79 | if (!isset($externalStorageGateways[$attribute['alias']])) { |
||
| 80 | throw new LogicException( |
||
| 81 | "External storage handler '$id' for field type {$attribute['alias']} needs a storage gateway but none was given. |
||
| 82 | Consider defining a storage gateway as a service for this field type and add the 'ezpublish.fieldType.externalStorageHandler.gateway tag'" |
||
| 83 | ); |
||
| 84 | } |
||
| 85 | |||
| 86 | $storageHandlerDef->addMethodCall( |
||
| 87 | 'addGateway', |
||
| 88 | [ |
||
| 89 | $externalStorageGateways[$attribute['alias']]['identifier'], |
||
| 90 | new Reference($externalStorageGateways[$attribute['alias']]['id']), |
||
| 91 | ] |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | |||
| 95 | $externalStorageRegistryFactoryDefinition->addMethodCall( |
||
| 96 | 'registerExternalStorageHandler', |
||
| 97 | [ |
||
| 98 | $id, |
||
| 99 | $attribute['alias'], |
||
| 100 | ] |
||
| 101 | ); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 |