| Conditions | 10 |
| Paths | 25 |
| Total Lines | 40 |
| 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 |
||
| 21 | public function process(ContainerBuilder $container) |
||
| 22 | { |
||
| 23 | if (!$container->has(PluginManager::class)) { |
||
| 24 | return; |
||
| 25 | } |
||
| 26 | |||
| 27 | $pluginsData = []; |
||
| 28 | |||
| 29 | // Find all Plugin services. |
||
| 30 | $plugins = $container->findTaggedServiceIds('expansion.plugin'); |
||
| 31 | foreach ($plugins as $id => $tags) { |
||
| 32 | $pluginsData[$id]['dataProviders'] = []; |
||
| 33 | foreach ($tags as $attributes) { |
||
| 34 | if (isset($attributes['data_provider'])) { |
||
| 35 | $pluginsData[$id]['dataProviders'][] = $attributes['data_provider']; |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | // Find the parent services. |
||
| 41 | $plugins = $container->findTaggedServiceIds('expansion.plugin.parent'); |
||
| 42 | foreach ($plugins as $id => $tags) { |
||
| 43 | foreach ($tags as $attributes) { |
||
| 44 | $pluginsData[$id]['parent'][] = $attributes['parent']; |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | // Get the data provider manager service definition to register data providers into. |
||
| 49 | $definition = $container->getDefinition(PluginManager::class); |
||
| 50 | |||
| 51 | foreach ($pluginsData as $pluginId => $data) |
||
| 52 | { |
||
| 53 | $definition->addMethodCall('registerPlugin', [ |
||
| 54 | $pluginId, |
||
| 55 | empty($data['dataProviders']) ? [] : $data['dataProviders'], |
||
| 56 | empty($data['parent']) ? [] : $data['parent'], |
||
| 57 | ] |
||
| 58 | ); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } |
||
| 62 |