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