Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
18 | class Configuration implements ConfigurationInterface |
||
19 | { |
||
20 | /** |
||
21 | * Stores supported database drivers. |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | private $supportedDrivers = ['orm', 'mongodb', 'propel', 'phpcr']; |
||
26 | |||
27 | /** |
||
28 | * If the kernel is running in debug mode. |
||
29 | * |
||
30 | * @var bool |
||
31 | */ |
||
32 | private $debug; |
||
33 | |||
34 | 17 | public function __construct($debug) |
|
38 | |||
39 | /** |
||
40 | * Generates the configuration tree. |
||
41 | * |
||
42 | * @return TreeBuilder |
||
43 | */ |
||
44 | 17 | public function getConfigTreeBuilder() |
|
73 | |||
74 | /** |
||
75 | * Returns the array node used for "dynamic_templates". |
||
76 | */ |
||
77 | 17 | public function getDynamicTemplateNode() |
|
104 | |||
105 | /** |
||
106 | * Returns the array node used for "types". |
||
107 | */ |
||
108 | 17 | protected function getTypesNode() |
|
164 | |||
165 | /** |
||
166 | * Returns the array node used for "properties". |
||
167 | */ |
||
168 | 17 | protected function getPropertiesNode() |
|
180 | |||
181 | /** |
||
182 | * Returns the array node used for "_id". |
||
183 | */ |
||
184 | 17 | View Code Duplication | protected function getIdNode() |
197 | |||
198 | /** |
||
199 | * Returns the array node used for "_source". |
||
200 | */ |
||
201 | 17 | protected function getSourceNode() |
|
224 | |||
225 | /** |
||
226 | * Returns the array node used for "_routing". |
||
227 | */ |
||
228 | 17 | View Code Duplication | protected function getRoutingNode() |
242 | |||
243 | /** |
||
244 | * Returns the array node used for "_parent". |
||
245 | */ |
||
246 | 17 | protected function getParentNode() |
|
261 | |||
262 | /** |
||
263 | * Returns the array node used for "_all". |
||
264 | */ |
||
265 | 17 | protected function getAllNode() |
|
279 | |||
280 | /** |
||
281 | * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
||
282 | */ |
||
283 | 17 | protected function getPersistenceNode() |
|
284 | { |
||
285 | 17 | $builder = new TreeBuilder(); |
|
286 | 17 | $node = $builder->root('persistence'); |
|
287 | |||
288 | $node |
||
289 | 17 | ->validate() |
|
290 | View Code Duplication | ->ifTrue(function ($v) { |
|
291 | return isset($v['driver']) && 'propel' === $v['driver'] && isset($v['listener']); |
||
292 | 17 | }) |
|
293 | 17 | ->thenInvalid('Propel doesn\'t support listeners') |
|
294 | View Code Duplication | ->ifTrue(function ($v) { |
|
295 | return isset($v['driver']) && 'propel' === $v['driver'] && isset($v['repository']); |
||
296 | 17 | }) |
|
297 | 17 | ->thenInvalid('Propel doesn\'t support the "repository" parameter') |
|
298 | ->ifTrue(function ($v) { |
||
299 | 6 | return isset($v['driver']) && 'orm' !== $v['driver'] && !empty($v['elastica_to_model_transformer']['hints']); |
|
300 | 17 | }) |
|
301 | 17 | ->thenInvalid('Hints are only supported by the "orm" driver') |
|
302 | 17 | ->end() |
|
303 | 17 | ->children() |
|
304 | 17 | ->scalarNode('driver') |
|
305 | 17 | ->defaultValue('orm') |
|
306 | 17 | ->validate() |
|
307 | 17 | ->ifNotInArray($this->supportedDrivers) |
|
308 | 17 | ->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($this->supportedDrivers)) |
|
309 | 17 | ->end() |
|
310 | 17 | ->end() |
|
311 | 17 | ->scalarNode('model')->defaultValue(null)->end() |
|
312 | 17 | ->scalarNode('repository')->end() |
|
313 | 17 | ->scalarNode('identifier')->defaultValue('id')->end() |
|
314 | 17 | ->arrayNode('provider') |
|
315 | 17 | ->addDefaultsIfNotSet() |
|
316 | 17 | ->children() |
|
317 | 17 | ->scalarNode('batch_size')->defaultValue(100)->end() |
|
318 | 17 | ->scalarNode('clear_object_manager')->defaultTrue()->end() |
|
319 | 17 | ->scalarNode('debug_logging') |
|
320 | 17 | ->defaultValue($this->debug) |
|
321 | 17 | ->treatNullLike(true) |
|
322 | 17 | ->end() |
|
323 | 17 | ->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end() |
|
324 | 17 | ->scalarNode('service')->end() |
|
325 | 17 | ->end() |
|
326 | 17 | ->end() |
|
327 | 17 | ->arrayNode('listener') |
|
328 | 17 | ->addDefaultsIfNotSet() |
|
329 | 17 | ->children() |
|
330 | 17 | ->scalarNode('insert')->defaultTrue()->end() |
|
331 | 17 | ->scalarNode('update')->defaultTrue()->end() |
|
332 | 17 | ->scalarNode('delete')->defaultTrue()->end() |
|
333 | 17 | ->scalarNode('flush')->defaultTrue()->end() |
|
334 | 17 | ->booleanNode('defer')->defaultFalse()->end() |
|
335 | 17 | ->scalarNode('logger') |
|
336 | 17 | ->defaultFalse() |
|
337 | 17 | ->treatNullLike('fos_elastica.logger') |
|
338 | 17 | ->treatTrueLike('fos_elastica.logger') |
|
339 | 17 | ->end() |
|
340 | 17 | ->scalarNode('service')->end() |
|
341 | 17 | ->end() |
|
342 | 17 | ->end() |
|
343 | 17 | ->arrayNode('finder') |
|
344 | 17 | ->addDefaultsIfNotSet() |
|
345 | 17 | ->children() |
|
346 | 17 | ->scalarNode('service')->end() |
|
347 | 17 | ->end() |
|
348 | 17 | ->end() |
|
349 | 17 | ->arrayNode('elastica_to_model_transformer') |
|
350 | 17 | ->addDefaultsIfNotSet() |
|
351 | 17 | ->children() |
|
352 | 17 | ->arrayNode('hints') |
|
353 | 17 | ->prototype('array') |
|
354 | 17 | ->children() |
|
355 | 17 | ->scalarNode('name')->end() |
|
356 | 17 | ->scalarNode('value')->end() |
|
357 | 17 | ->end() |
|
358 | 17 | ->end() |
|
359 | 17 | ->end() |
|
360 | 17 | ->booleanNode('hydrate')->defaultTrue()->end() |
|
361 | 17 | ->booleanNode('ignore_missing') |
|
362 | 17 | ->defaultFalse() |
|
363 | 17 | ->info('Silently ignore results returned from Elasticsearch without corresponding persistent object.') |
|
364 | 17 | ->end() |
|
365 | 17 | ->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end() |
|
366 | 17 | ->scalarNode('service')->end() |
|
367 | 17 | ->end() |
|
368 | 17 | ->end() |
|
369 | 17 | ->arrayNode('model_to_elastica_transformer') |
|
370 | 17 | ->addDefaultsIfNotSet() |
|
371 | 17 | ->children() |
|
372 | 17 | ->scalarNode('service')->end() |
|
373 | 17 | ->end() |
|
374 | 17 | ->end() |
|
375 | 17 | ->arrayNode('persister') |
|
376 | 17 | ->addDefaultsIfNotSet() |
|
377 | 17 | ->children() |
|
378 | 17 | ->scalarNode('service')->end() |
|
379 | 17 | ->end() |
|
380 | 17 | ->end() |
|
381 | 17 | ->end(); |
|
382 | |||
383 | 17 | return $node; |
|
384 | } |
||
385 | |||
386 | /** |
||
387 | * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
||
388 | */ |
||
389 | 17 | protected function getSerializerNode() |
|
409 | |||
410 | /** |
||
411 | * Adds the configuration for the "clients" key. |
||
412 | */ |
||
413 | 17 | private function addClientsSection(ArrayNodeDefinition $rootNode) |
|
414 | { |
||
415 | $rootNode |
||
416 | 17 | ->fixXmlConfig('client') |
|
417 | 17 | ->children() |
|
418 | 17 | ->arrayNode('clients') |
|
419 | 17 | ->useAttributeAsKey('id') |
|
420 | 17 | ->prototype('array') |
|
421 | 17 | ->performNoDeepMerging() |
|
422 | // Elastica names its properties with camel case, support both |
||
423 | 17 | ->beforeNormalization() |
|
424 | ->ifTrue(function ($v) { |
||
425 | 16 | return isset($v['connection_strategy']); |
|
426 | 17 | }) |
|
427 | ->then(function ($v) { |
||
428 | 1 | $v['connectionStrategy'] = $v['connection_strategy']; |
|
429 | 1 | unset($v['connection_strategy']); |
|
430 | |||
431 | 1 | return $v; |
|
432 | 17 | }) |
|
433 | 17 | ->end() |
|
434 | // If there is no connections array key defined, assume a single connection. |
||
435 | 17 | ->beforeNormalization() |
|
436 | ->ifTrue(function ($v) { |
||
437 | 16 | return is_array($v) && !array_key_exists('connections', $v); |
|
438 | 17 | }) |
|
439 | ->then(function ($v) { |
||
440 | return [ |
||
441 | 16 | 'connections' => [$v], |
|
442 | 16 | ]; |
|
443 | 17 | }) |
|
444 | 17 | ->end() |
|
445 | 17 | ->children() |
|
446 | 17 | ->arrayNode('connections') |
|
447 | 17 | ->requiresAtLeastOneElement() |
|
448 | 17 | ->prototype('array') |
|
449 | 17 | ->fixXmlConfig('header') |
|
450 | 17 | ->children() |
|
451 | 17 | ->scalarNode('url') |
|
452 | 17 | ->validate() |
|
453 | ->ifTrue(function ($url) { |
||
454 | 12 | return $url && '/' !== substr($url, -1); |
|
455 | 17 | }) |
|
456 | 17 | ->then(function ($url) { |
|
457 | 12 | return $url.'/'; |
|
458 | 17 | }) |
|
459 | 17 | ->end() |
|
460 | 17 | ->end() |
|
461 | 17 | ->scalarNode('username')->end() |
|
462 | 17 | ->scalarNode('password')->end() |
|
463 | 17 | ->scalarNode('host')->end() |
|
464 | 17 | ->scalarNode('port')->end() |
|
465 | 17 | ->scalarNode('proxy')->end() |
|
466 | 17 | ->scalarNode('aws_access_key_id')->end() |
|
467 | 17 | ->scalarNode('aws_secret_access_key')->end() |
|
468 | 17 | ->scalarNode('aws_region')->end() |
|
469 | 17 | ->scalarNode('aws_session_token')->end() |
|
470 | 17 | ->booleanNode('ssl')->defaultValue(false)->end() |
|
471 | 17 | ->scalarNode('logger') |
|
472 | 17 | ->defaultValue($this->debug ? 'fos_elastica.logger' : false) |
|
473 | 17 | ->treatNullLike('fos_elastica.logger') |
|
474 | 17 | ->treatTrueLike('fos_elastica.logger') |
|
475 | 17 | ->end() |
|
476 | 17 | ->booleanNode('compression')->defaultValue(false)->end() |
|
477 | 17 | ->arrayNode('headers') |
|
478 | 17 | ->normalizeKeys(false) |
|
479 | 17 | ->useAttributeAsKey('name') |
|
480 | 17 | ->prototype('scalar')->end() |
|
481 | 17 | ->end() |
|
482 | 17 | ->arrayNode('curl') |
|
483 | 17 | ->useAttributeAsKey(CURLOPT_SSL_VERIFYPEER) |
|
484 | 17 | ->prototype('boolean')->end() |
|
485 | 17 | ->end() |
|
486 | 17 | ->scalarNode('transport')->end() |
|
487 | 17 | ->scalarNode('timeout')->end() |
|
488 | 17 | ->scalarNode('connectTimeout')->end() |
|
489 | 17 | ->scalarNode('retryOnConflict') |
|
490 | 17 | ->defaultValue(0) |
|
491 | 17 | ->end() |
|
492 | 17 | ->end() |
|
493 | 17 | ->end() |
|
494 | 17 | ->end() |
|
495 | 17 | ->scalarNode('timeout')->end() |
|
496 | 17 | ->scalarNode('connectTimeout')->end() |
|
497 | 17 | ->scalarNode('headers')->end() |
|
498 | 17 | ->scalarNode('connectionStrategy')->defaultValue('Simple')->end() |
|
499 | 17 | ->end() |
|
500 | 17 | ->end() |
|
501 | 17 | ->end() |
|
502 | 17 | ->end() |
|
503 | ; |
||
504 | 17 | } |
|
505 | |||
506 | /** |
||
507 | * Adds the configuration for the "indexes" key. |
||
508 | */ |
||
509 | 17 | private function addIndexesSection(ArrayNodeDefinition $rootNode) |
|
542 | } |
||
543 |
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.