Conditions | 29 |
Paths | 4 |
Total Lines | 250 |
Code Lines | 206 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
83 | private function createClientsNode() : ArrayNodeDefinition |
||
84 | { |
||
85 | $builder = new TreeBuilder('clients'); |
||
86 | |||
87 | /** @var \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition $node */ |
||
88 | if (method_exists($builder, 'getRootNode')) { |
||
89 | $node = $builder->getRootNode(); |
||
90 | } else { |
||
91 | // BC layer for symfony/config 4.1 and older |
||
92 | $node = $builder->root('clients'); |
||
93 | } |
||
94 | |||
95 | /** @var \Symfony\Component\Config\Definition\Builder\NodeBuilder $nodeChildren */ |
||
96 | $nodeChildren = $node->useAttributeAsKey('name') |
||
97 | ->prototype('array') |
||
98 | ->children(); |
||
99 | |||
100 | $nodeChildren->scalarNode('class')->defaultValue('%eight_points_guzzle.http_client.class%')->end() |
||
101 | ->scalarNode('base_url') |
||
102 | ->defaultValue(null) |
||
103 | ->validate() |
||
104 | ->ifTrue(function ($v) { |
||
105 | return !is_string($v); |
||
106 | }) |
||
107 | ->thenInvalid('base_url can be: string') |
||
108 | ->end() |
||
109 | ->end() |
||
110 | ->booleanNode('lazy')->defaultValue(false)->end() |
||
111 | ->integerNode('logging') |
||
112 | ->defaultValue(null) |
||
113 | ->beforeNormalization() |
||
114 | ->always(\Closure::fromCallable([$this, 'checkLoggingMode'])) |
||
115 | ->end() |
||
116 | ->end() |
||
117 | ->scalarNode('handler') |
||
118 | ->defaultValue(null) |
||
119 | ->validate() |
||
120 | ->ifTrue(function ($v) { |
||
121 | return $v !== null && (!is_string($v) || !class_exists($v)); |
||
122 | }) |
||
123 | ->thenInvalid('handler must be a valid FQCN for a loaded class') |
||
124 | ->end() |
||
125 | ->end() |
||
126 | ->arrayNode('options') |
||
127 | ->validate() |
||
128 | ->ifTrue(function ($options) { |
||
129 | return count($options['form_params']) && count($options['multipart']); |
||
130 | }) |
||
131 | ->thenInvalid('You cannot use form_params and multipart at the same time.') |
||
132 | ->end() |
||
133 | ->children() |
||
134 | ->arrayNode('headers') |
||
135 | ->useAttributeAsKey('name') |
||
136 | ->normalizeKeys(false) |
||
137 | ->prototype('scalar')->end() |
||
138 | ->end() |
||
139 | ->variableNode('allow_redirects') |
||
140 | ->validate() |
||
141 | ->ifTrue(function ($v) { |
||
142 | return !is_array($v) && !is_bool($v); |
||
143 | }) |
||
144 | ->thenInvalid('allow_redirects can be: bool or array') |
||
145 | ->end() |
||
146 | ->end() |
||
147 | ->variableNode('auth') |
||
148 | ->validate() |
||
149 | ->ifTrue(function ($v) { |
||
150 | return !is_array($v) && !is_string($v); |
||
151 | }) |
||
152 | ->thenInvalid('auth can be: string or array') |
||
153 | ->end() |
||
154 | ->end() |
||
155 | ->variableNode('query') |
||
156 | ->validate() |
||
157 | ->ifTrue(function ($v) { |
||
158 | return !is_string($v) && !is_array($v); |
||
159 | }) |
||
160 | ->thenInvalid('query can be: string or array') |
||
161 | ->end() |
||
162 | ->end() |
||
163 | ->arrayNode('curl') |
||
164 | ->beforeNormalization() |
||
165 | ->ifArray() |
||
166 | ->then(function (array $curlOptions) { |
||
167 | $result = []; |
||
168 | |||
169 | foreach ($curlOptions as $key => $value) { |
||
170 | $optionName = 'CURLOPT_' . strtoupper($key); |
||
171 | |||
172 | if (!defined($optionName)) { |
||
173 | throw new InvalidConfigurationException(sprintf( |
||
174 | 'Invalid curl option in eight_points_guzzle: %s. ' . |
||
175 | 'Ex: use sslversion for CURLOPT_SSLVERSION option. ' . PHP_EOL . |
||
176 | 'See all available options: http://php.net/manual/en/function.curl-setopt.php', |
||
177 | $key |
||
178 | )); |
||
179 | } |
||
180 | |||
181 | $result[constant($optionName)] = $value; |
||
182 | } |
||
183 | |||
184 | return $result; |
||
185 | }) |
||
186 | ->end() |
||
187 | ->prototype('scalar') |
||
188 | ->end() |
||
189 | ->end() |
||
190 | ->variableNode('cert') |
||
191 | ->validate() |
||
192 | ->ifTrue(function ($v) { |
||
193 | return !is_string($v) && (!is_array($v) || count($v) !== 2); |
||
194 | }) |
||
195 | ->thenInvalid('cert can be: string or array with two entries (path and password)') |
||
196 | ->end() |
||
197 | ->end() |
||
198 | ->scalarNode('connect_timeout') |
||
199 | ->beforeNormalization() |
||
200 | ->always(function ($v) { |
||
201 | return is_numeric($v) ? (float) $v : $v; |
||
202 | }) |
||
203 | ->end() |
||
204 | ->validate() |
||
205 | ->ifTrue(function ($v) { |
||
206 | return !is_float($v) && !(is_string($v) && strpos($v, 'env_') === 0); |
||
207 | }) |
||
208 | ->thenInvalid('connect_timeout can be: float') |
||
209 | ->end() |
||
210 | ->end() |
||
211 | ->booleanNode('debug')->end() |
||
212 | ->variableNode('decode_content') |
||
213 | ->validate() |
||
214 | ->ifTrue(function ($v) { |
||
215 | return !is_string($v) && !is_bool($v); |
||
216 | }) |
||
217 | ->thenInvalid('decode_content can be: bool or string (gzip, compress, deflate, etc...)') |
||
218 | ->end() |
||
219 | ->end() |
||
220 | ->floatNode('delay')->end() |
||
221 | ->arrayNode('form_params') |
||
222 | ->useAttributeAsKey('name') |
||
223 | ->prototype('variable')->end() |
||
224 | ->end() |
||
225 | ->arrayNode('multipart') |
||
226 | ->prototype('variable')->end() |
||
227 | ->end() |
||
228 | ->scalarNode('sink') |
||
229 | ->validate() |
||
230 | ->ifTrue(function ($v) { |
||
231 | return !is_string($v); |
||
232 | }) |
||
233 | ->thenInvalid('sink can be: string') |
||
234 | ->end() |
||
235 | ->end() |
||
236 | ->booleanNode('http_errors')->end() |
||
237 | ->variableNode('expect') |
||
238 | ->validate() |
||
239 | ->ifTrue(function ($v) { |
||
240 | return !is_bool($v) && !is_int($v); |
||
241 | }) |
||
242 | ->thenInvalid('expect can be: bool or int') |
||
243 | ->end() |
||
244 | ->end() |
||
245 | ->variableNode('ssl_key') |
||
246 | ->validate() |
||
247 | ->ifTrue(function ($v) { |
||
248 | return !is_string($v) && (!is_array($v) || count($v) !== 2); |
||
249 | }) |
||
250 | ->thenInvalid('ssl_key can be: string or array with two entries (path and password)') |
||
251 | ->end() |
||
252 | ->end() |
||
253 | ->booleanNode('stream')->end() |
||
254 | ->booleanNode('synchronous')->end() |
||
255 | ->scalarNode('read_timeout') |
||
256 | ->beforeNormalization() |
||
257 | ->always(function ($v) { |
||
258 | return is_numeric($v) ? (float) $v : $v; |
||
259 | }) |
||
260 | ->end() |
||
261 | ->validate() |
||
262 | ->ifTrue(function ($v) { |
||
263 | return !is_float($v) && !(is_string($v) && strpos($v, 'env_') === 0); |
||
264 | }) |
||
265 | ->thenInvalid('read_timeout can be: float') |
||
266 | ->end() |
||
267 | ->end() |
||
268 | ->scalarNode('timeout') |
||
269 | ->beforeNormalization() |
||
270 | ->always(function ($v) { |
||
271 | return is_numeric($v) ? (float) $v : $v; |
||
272 | }) |
||
273 | ->end() |
||
274 | ->validate() |
||
275 | ->ifTrue(function ($v) { |
||
276 | return !is_float($v) && !(is_string($v) && strpos($v, 'env_') === 0); |
||
277 | }) |
||
278 | ->thenInvalid('timeout can be: float') |
||
279 | ->end() |
||
280 | ->end() |
||
281 | ->variableNode('verify') |
||
282 | ->validate() |
||
283 | ->ifTrue(function ($v) { |
||
284 | return !is_bool($v) && !is_string($v); |
||
285 | }) |
||
286 | ->thenInvalid('verify can be: bool or string') |
||
287 | ->end() |
||
288 | ->end() |
||
289 | ->booleanNode('cookies')->end() |
||
290 | ->arrayNode('proxy') |
||
291 | ->beforeNormalization() |
||
292 | ->ifString() |
||
293 | ->then(function($v) { return ['http'=> $v]; }) |
||
294 | ->end() |
||
295 | ->validate() |
||
296 | ->always(function($v) { |
||
297 | if (empty($v['no'])) { |
||
298 | unset($v['no']); |
||
299 | } |
||
300 | return $v; |
||
301 | }) |
||
302 | ->end() |
||
303 | ->children() |
||
304 | ->scalarNode('http')->end() |
||
305 | ->scalarNode('https')->end() |
||
306 | ->arrayNode('no') |
||
307 | ->prototype('scalar')->end() |
||
308 | ->end() |
||
309 | ->end() |
||
310 | ->end() |
||
311 | ->scalarNode('version') |
||
312 | ->validate() |
||
313 | ->ifTrue(function ($v) { |
||
314 | return !is_string($v) && !is_float($v); |
||
315 | }) |
||
316 | ->thenInvalid('version can be: string or float') |
||
317 | ->end() |
||
318 | ->end() |
||
319 | ->end() |
||
320 | ->end(); |
||
321 | |||
322 | $pluginsNode = $nodeChildren->arrayNode('plugin')->addDefaultsIfNotSet(); |
||
323 | |||
324 | foreach ($this->plugins as $plugin) { |
||
325 | $pluginNode = new ArrayNodeDefinition($plugin->getPluginName()); |
||
326 | |||
327 | $plugin->addConfiguration($pluginNode); |
||
328 | |||
329 | $pluginsNode->children()->append($pluginNode); |
||
330 | } |
||
331 | |||
332 | return $node; |
||
333 | } |
||
346 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.