| Conditions | 16 |
| Paths | 541 |
| Total Lines | 69 |
| Code Lines | 37 |
| 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('expansion.framework.core.services.data_provider_manager')) { |
||
| 24 | return; |
||
| 25 | } |
||
| 26 | |||
| 27 | // Get the data provider manager service definition to register plugins into. |
||
| 28 | $dpmDefinition = $container->getDefinition('expansion.framework.core.services.data_provider_manager'); |
||
| 29 | $pmDefinition = $container->getDefinition('expansion.framework.core.services.plugin_manager'); |
||
| 30 | |||
| 31 | $providerData = []; |
||
| 32 | |||
| 33 | // Get provider service names. |
||
| 34 | $dataProviders = $container->findTaggedServiceIds('expansion.data_provider'); |
||
| 35 | foreach ($dataProviders as $id => $tags) { |
||
| 36 | foreach ($tags as $attributes) { |
||
| 37 | $providerData[$id]['provider'] = $attributes['provider']; |
||
| 38 | $providerData[$id]['interface'] = $attributes['interface']; |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | // Get compatibility information for each provider |
||
| 43 | $dataProviders = $container->findTaggedServiceIds('expansion.data_provider.compatibility'); |
||
| 44 | foreach ($dataProviders as $id => $tags) { |
||
| 45 | foreach ($tags as $attributes) { |
||
| 46 | $providerData[$id]['compatibility'][] = [ |
||
| 47 | 'title' => isset($attributes['title']) ? $attributes['title'] : DataProviderManager::COMPATIBLE_ALL, |
||
| 48 | 'mode' => isset($attributes['mode']) ? $attributes['mode'] : DataProviderManager::COMPATIBLE_ALL, |
||
| 49 | 'script' => isset($attributes['script']) ? $attributes['script'] : DataProviderManager::COMPATIBLE_ALL, |
||
| 50 | ]; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | // Get base events the data provider needs to listen to. |
||
| 55 | $dataProviders = $container->findTaggedServiceIds('expansion.data_provider.listener'); |
||
| 56 | foreach ($dataProviders as $id => $tags) { |
||
| 57 | foreach ($tags as $attributes) { |
||
| 58 | $providerData[$id]['listener'][$attributes['event_name']] = $attributes['method']; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | // Get parent plugins the data provider requires. |
||
| 63 | $plugins = $container->findTaggedServiceIds('expansion.data_provider.parent'); |
||
| 64 | foreach ($plugins as $id => $tags) { |
||
| 65 | foreach ($tags as $attributes) { |
||
| 66 | $providerData[$id]['parent'][] = $attributes['parent']; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | // Finally register collected data. |
||
| 71 | foreach ($providerData as $id => $data) { |
||
| 72 | $dpmDefinition->addMethodCall('registerDataProvider', [ |
||
| 73 | $id, |
||
| 74 | $data['provider'], |
||
| 75 | $data['interface'], |
||
| 76 | $data['compatibility'], |
||
| 77 | !empty($data['listener']) ? $data['listener'] : [], |
||
| 78 | ] |
||
| 79 | ); |
||
| 80 | |||
| 81 | $pmDefinition->addMethodCall('registerPlugin', [ |
||
| 82 | $id, |
||
| 83 | [], |
||
| 84 | isset($data['parent']) ? $data['parent'] : [], |
||
| 85 | $data['provider'], |
||
| 86 | ] |
||
| 87 | ); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |