Conditions | 8 |
Paths | 15 |
Total Lines | 55 |
Code Lines | 31 |
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 |
||
31 | public function process(ContainerBuilder $container) |
||
32 | { |
||
33 | $filters = []; |
||
34 | foreach ($container->findTaggedServiceIds('ongr_filter_manager.filter') as $filterId => $filterTags) { |
||
35 | $tagOptions = array_shift($filterTags); |
||
36 | |||
37 | if (!array_key_exists('type', $tagOptions)) { |
||
38 | throw new InvalidConfigurationException( |
||
39 | sprintf('Filter service `%s` must have `type` set.', $filterId) |
||
40 | ); |
||
41 | } |
||
42 | |||
43 | $filters[$tagOptions['type']] = $filterId; |
||
44 | } |
||
45 | |||
46 | foreach ($container->getParameter('ongr_filter_manager.filters') as $filterName => $filterOptions) { |
||
47 | if (!array_key_exists($filterOptions['type'], $filters)) { |
||
48 | throw new InvalidConfigurationException( |
||
49 | "There is no `{$filterOptions['type']}` type filter registered." |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | $definition = new ChildDefinition($filters[($filterOptions['type'])]); |
||
54 | $definition->addMethodCall('setRequestField', [$filterOptions['request_field']]); |
||
55 | $definition->addMethodCall('setDocumentField', [$filterOptions['document_field']]); |
||
56 | $definition->addMethodCall('setTags', [$filterOptions['tags']]); |
||
57 | $definition->addMethodCall('setOptions', [$filterOptions['options']]); |
||
58 | |||
59 | $container->setDefinition(ONGRFilterManagerExtension::getFilterId($filterName), $definition); |
||
60 | } |
||
61 | |||
62 | foreach ($container->getParameter('ongr_filter_manager.managers') as $managerName => $managerOptions) { |
||
63 | $filterContainer = new Definition('ONGR\FilterManagerBundle\Search\FilterContainer'); |
||
64 | |||
65 | if (isset($managerOptions['filters'])) { |
||
66 | foreach ($managerOptions['filters'] as $filter) { |
||
67 | $filterContainer->addMethodCall( |
||
68 | 'set', |
||
69 | [$filter, new Reference(ONGRFilterManagerExtension::getFilterId($filter))] |
||
70 | ); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | $managerDefinition = new Definition( |
||
75 | 'ONGR\FilterManagerBundle\Search\FilterManager', |
||
76 | [ |
||
77 | $filterContainer, |
||
78 | new Reference($managerOptions['repository']), |
||
79 | new Reference('event_dispatcher'), |
||
80 | ] |
||
81 | ); |
||
82 | |||
83 | $container->setDefinition(ONGRFilterManagerExtension::getFilterManagerId($managerName), $managerDefinition); |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 |