Conditions | 9 |
Paths | 9 |
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 |
||
57 | private function handleDirectoryMapping(ContainerBuilder $container, string $dir): void |
||
58 | { |
||
59 | /** @var DocumentParser $parser */ |
||
60 | $parser = $container->get(DocumentParser::class); |
||
61 | $indexesOverride = $container->getParameter(Configuration::ONGR_INDEXES_OVERRIDE); |
||
62 | $converterDefinition = $container->getDefinition(Converter::class); |
||
63 | |||
64 | foreach ($this->getNamespaces($dir) as $namespace) { |
||
65 | $class = new \ReflectionClass($namespace); |
||
66 | |||
67 | if (isset($indexesOverride[$namespace]['alias']) && $indexesOverride[$namespace]['alias']) { |
||
68 | $indexAlias = $indexesOverride[$namespace]['alias']; |
||
69 | } else { |
||
70 | $indexAlias = $parser->getIndexAliasName($class); |
||
71 | } |
||
72 | |||
73 | /** @var Index $document */ |
||
74 | $document = $parser->getIndexAnnotation($class); |
||
75 | $indexMetadata = $parser->getIndexMetadata($class); |
||
76 | |||
77 | if (!empty($indexMetadata)) { |
||
78 | $indexMetadata['settings'] = array_filter(array_merge_recursive( |
||
79 | $indexMetadata['settings'] ?? [], |
||
80 | [ |
||
81 | 'number_of_replicas' => $document->numberOfReplicas, |
||
82 | 'number_of_shards' => $document->numberOfShards, |
||
83 | ], |
||
84 | $indexesOverride[$namespace]['settings'] ?? [] |
||
85 | )); |
||
86 | |||
87 | $indexSettings = new Definition( |
||
88 | IndexSettings::class, |
||
89 | [ |
||
90 | $namespace, |
||
91 | $indexAlias, |
||
92 | $indexAlias, |
||
93 | $indexMetadata, |
||
94 | $indexesOverride[$namespace]['hosts'] ?? $document->hosts, |
||
95 | $indexesOverride[$namespace]['default'] ?? $document->default, |
||
96 | $indexesOverride[$namespace]['type'] ?? $document->typeName |
||
|
|||
97 | ] |
||
98 | ); |
||
99 | |||
100 | $indexServiceDefinition = new Definition(IndexService::class, [ |
||
101 | $namespace, |
||
102 | $converterDefinition, |
||
103 | $container->getDefinition('event_dispatcher'), |
||
104 | $indexSettings, |
||
105 | $container->getParameter(Configuration::ONGR_PROFILER_CONFIG) |
||
106 | ? $container->getDefinition('ongr.esb.tracer') : null |
||
107 | ]); |
||
108 | $indexServiceDefinition->setPublic(true); |
||
109 | $converterDefinition->addMethodCall( |
||
110 | 'addClassMetadata', |
||
111 | [ |
||
112 | $namespace, |
||
113 | $parser->getPropertyMetadata($class) |
||
114 | ] |
||
115 | ); |
||
116 | |||
117 | $container->setDefinition($namespace, $indexServiceDefinition); |
||
118 | $this->indexes[$indexAlias] = $namespace; |
||
119 | $isCurrentIndexDefault = $parser->isDefaultIndex($class); |
||
120 | if ($this->defaultIndex && $isCurrentIndexDefault) { |
||
121 | throw new \RuntimeException( |
||
122 | sprintf( |
||
123 | 'Only one index can be set as default. We found 2 indexes as default ones `%s` and `%s`', |
||
124 | $this->defaultIndex, |
||
125 | $indexAlias |
||
126 | ) |
||
127 | ); |
||
128 | } |
||
129 | |||
130 | if ($isCurrentIndexDefault) { |
||
131 | $this->defaultIndex = $indexAlias; |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | |||
176 |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.