Conditions | 9 |
Paths | 9 |
Total Lines | 78 |
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 | if (!isset($indexClasses[$class])) { |
||
58 | throw new \RuntimeException( |
||
59 | sprintf( |
||
60 | 'Document `%s` defined in ongr_elasticsearch.indexes config could not been found', |
||
61 | $class |
||
62 | ) |
||
63 | ); |
||
64 | } |
||
65 | |||
66 | $indexSettings = $this->parseIndexSettingsFromClass($parser, $class); |
||
|
|||
67 | |||
68 | if ($class !== $name) { |
||
69 | $indexSettings->setIndexName('ongr.es.index.'.$name); |
||
70 | } |
||
71 | |||
72 | if (isset($indexOverride['alias'])) { |
||
73 | $indexSettings->setAlias($indexOverride['alias']); |
||
74 | } |
||
75 | |||
76 | if (isset($indexOverride['settings'])) { |
||
77 | $indexSettings->setIndexMetadata($indexOverride['settings']); |
||
78 | } |
||
79 | |||
80 | if (isset($indexOverride['hosts'])) { |
||
81 | $indexSettings->setHosts($indexOverride['hosts']); |
||
82 | } |
||
83 | |||
84 | if (isset($indexOverride['default'])) { |
||
85 | $indexSettings->setDefaultIndex($indexOverride['default']); |
||
86 | } |
||
87 | |||
88 | $indexSettingsArray[$name] = $indexSettings; |
||
89 | $overwrittenClasses[$class] = $class; |
||
90 | } |
||
91 | |||
92 | foreach (array_diff($indexClasses, $overwrittenClasses) as $indexClass) { |
||
93 | try { |
||
94 | $indexSettingsArray[$indexClass] = $this->parseIndexSettingsFromClass($parser, $indexClass); |
||
95 | } catch (DocumentIndexParserException $e) { |
||
96 | } |
||
97 | } |
||
98 | |||
99 | foreach ($indexSettingsArray as $indexSettings) { |
||
100 | $this->createIndex($container, $indexSettings); |
||
101 | } |
||
102 | |||
103 | $container->setParameter(Configuration::ONGR_INDEXES, $this->indexes); |
||
104 | $container->setParameter( |
||
105 | Configuration::ONGR_DEFAULT_INDEX, |
||
106 | $this->defaultIndex ?? current(array_keys($this->indexes)) |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | private function parseIndexSettingsFromClass(DocumentParser $parser, string $className) : IndexSettings |
||
111 | { |
||
112 | $class = new \ReflectionClass($className); |
||
113 | |||
114 | /** @var Index $document */ |
||
115 | $document = $parser->getIndexAnnotation($class); |
||
116 | |||
117 | if ($document === null) { |
||
118 | throw new DocumentIndexParserException(); |
||
119 | } |
||
120 | |||
121 | $indexSettings = new IndexSettings( |
||
122 | $className, |
||
123 | $className, |
||
124 | $parser->getIndexAliasName($class), |
||
125 | $parser->getIndexMetadata($class), |
||
126 | $parser->getPropertyMetadata($class), |
||
127 | $document->hosts, |
||
128 | $parser->isDefaultIndex($class) |
||
129 | ); |
||
130 | |||
131 | $indexSettings->setIndexMetadata(['settings' => [ |
||
132 | 'number_of_replicas' => $document->numberOfReplicas, |
||
133 | 'number_of_shards' => $document->numberOfShards, |
||
134 | ]]); |
||
135 | |||
231 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: