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 | * Adds the configuration for the "clients" key. |
||
| 76 | */ |
||
| 77 | 17 | private function addClientsSection(ArrayNodeDefinition $rootNode) |
|
| 168 | |||
| 169 | /** |
||
| 170 | * Adds the configuration for the "indexes" key. |
||
| 171 | */ |
||
| 172 | 17 | private function addIndexesSection(ArrayNodeDefinition $rootNode) |
|
| 205 | |||
| 206 | /** |
||
| 207 | * Returns the array node used for "types". |
||
| 208 | */ |
||
| 209 | 17 | protected function getTypesNode() |
|
| 265 | |||
| 266 | /** |
||
| 267 | * Returns the array node used for "properties". |
||
| 268 | */ |
||
| 269 | 17 | protected function getPropertiesNode() |
|
| 281 | |||
| 282 | /** |
||
| 283 | * Returns the array node used for "dynamic_templates". |
||
| 284 | */ |
||
| 285 | 17 | public function getDynamicTemplateNode() |
|
| 312 | |||
| 313 | /** |
||
| 314 | * Returns the array node used for "_id". |
||
| 315 | */ |
||
| 316 | 17 | View Code Duplication | protected function getIdNode() |
| 329 | |||
| 330 | /** |
||
| 331 | * Returns the array node used for "_source". |
||
| 332 | */ |
||
| 333 | 17 | protected function getSourceNode() |
|
| 356 | |||
| 357 | /** |
||
| 358 | * Returns the array node used for "_routing". |
||
| 359 | */ |
||
| 360 | 17 | View Code Duplication | protected function getRoutingNode() |
| 374 | |||
| 375 | /** |
||
| 376 | * Returns the array node used for "_parent". |
||
| 377 | */ |
||
| 378 | 17 | protected function getParentNode() |
|
| 393 | |||
| 394 | /** |
||
| 395 | * Returns the array node used for "_all". |
||
| 396 | */ |
||
| 397 | 17 | protected function getAllNode() |
|
| 411 | |||
| 412 | /** |
||
| 413 | * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
||
| 414 | */ |
||
| 415 | 17 | protected function getPersistenceNode() |
|
| 416 | { |
||
| 417 | 17 | $builder = new TreeBuilder(); |
|
| 418 | 17 | $node = $builder->root('persistence'); |
|
| 419 | |||
| 420 | $node |
||
| 421 | 17 | ->validate() |
|
| 422 | View Code Duplication | ->ifTrue(function ($v) { |
|
| 423 | return isset($v['driver']) && 'propel' === $v['driver'] && isset($v['listener']); |
||
| 424 | 17 | }) |
|
| 425 | 17 | ->thenInvalid('Propel doesn\'t support listeners') |
|
| 426 | View Code Duplication | ->ifTrue(function ($v) { |
|
| 427 | return isset($v['driver']) && 'propel' === $v['driver'] && isset($v['repository']); |
||
| 428 | 17 | }) |
|
| 429 | 17 | ->thenInvalid('Propel doesn\'t support the "repository" parameter') |
|
| 430 | 17 | ->ifTrue(function ($v) { |
|
| 431 | 6 | return isset($v['driver']) && 'orm' !== $v['driver'] && !empty($v['elastica_to_model_transformer']['hints']); |
|
| 432 | 17 | }) |
|
| 433 | 17 | ->thenInvalid('Hints are only supported by the "orm" driver') |
|
| 434 | 17 | ->end() |
|
| 435 | 17 | ->children() |
|
| 436 | 17 | ->scalarNode('driver') |
|
| 437 | 17 | ->defaultValue('orm') |
|
| 438 | 17 | ->validate() |
|
| 439 | 17 | ->ifNotInArray($this->supportedDrivers) |
|
| 440 | 17 | ->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($this->supportedDrivers)) |
|
| 441 | 17 | ->end() |
|
| 442 | 17 | ->end() |
|
| 443 | 17 | ->scalarNode('model')->defaultValue(null)->end() |
|
| 444 | 17 | ->scalarNode('repository')->end() |
|
| 445 | 17 | ->scalarNode('identifier')->defaultValue('id')->end() |
|
| 446 | 17 | ->arrayNode('provider') |
|
| 447 | 17 | ->addDefaultsIfNotSet() |
|
| 448 | 17 | ->children() |
|
| 449 | 17 | ->scalarNode('batch_size')->defaultValue(100)->end() |
|
| 450 | 17 | ->scalarNode('clear_object_manager')->defaultTrue()->end() |
|
| 451 | 17 | ->scalarNode('debug_logging') |
|
| 452 | 17 | ->defaultValue($this->debug) |
|
| 453 | 17 | ->treatNullLike(true) |
|
| 454 | 17 | ->end() |
|
| 455 | 17 | ->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end() |
|
| 456 | 17 | ->scalarNode('service')->end() |
|
| 457 | 17 | ->end() |
|
| 458 | 17 | ->end() |
|
| 459 | 17 | ->arrayNode('listener') |
|
| 460 | 17 | ->addDefaultsIfNotSet() |
|
| 461 | 17 | ->children() |
|
| 462 | 17 | ->scalarNode('insert')->defaultTrue()->end() |
|
| 463 | 17 | ->scalarNode('update')->defaultTrue()->end() |
|
| 464 | 17 | ->scalarNode('delete')->defaultTrue()->end() |
|
| 465 | 17 | ->scalarNode('flush')->defaultTrue()->end() |
|
| 466 | 17 | ->booleanNode('defer')->defaultFalse()->end() |
|
| 467 | 17 | ->scalarNode('logger') |
|
| 468 | 17 | ->defaultFalse() |
|
| 469 | 17 | ->treatNullLike('fos_elastica.logger') |
|
| 470 | 17 | ->treatTrueLike('fos_elastica.logger') |
|
| 471 | 17 | ->end() |
|
| 472 | 17 | ->scalarNode('service')->end() |
|
| 473 | 17 | ->end() |
|
| 474 | 17 | ->end() |
|
| 475 | 17 | ->arrayNode('finder') |
|
| 476 | 17 | ->addDefaultsIfNotSet() |
|
| 477 | 17 | ->children() |
|
| 478 | 17 | ->scalarNode('service')->end() |
|
| 479 | 17 | ->end() |
|
| 480 | 17 | ->end() |
|
| 481 | 17 | ->arrayNode('elastica_to_model_transformer') |
|
| 482 | 17 | ->addDefaultsIfNotSet() |
|
| 483 | 17 | ->children() |
|
| 484 | 17 | ->arrayNode('hints') |
|
| 485 | 17 | ->prototype('array') |
|
| 486 | 17 | ->children() |
|
| 487 | 17 | ->scalarNode('name')->end() |
|
| 488 | 17 | ->scalarNode('value')->end() |
|
| 489 | 17 | ->end() |
|
| 490 | 17 | ->end() |
|
| 491 | 17 | ->end() |
|
| 492 | 17 | ->booleanNode('hydrate')->defaultTrue()->end() |
|
| 493 | 17 | ->booleanNode('ignore_missing') |
|
| 494 | 17 | ->defaultFalse() |
|
| 495 | 17 | ->info('Silently ignore results returned from Elasticsearch without corresponding persistent object.') |
|
| 496 | 17 | ->end() |
|
| 497 | 17 | ->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end() |
|
| 498 | 17 | ->scalarNode('service')->end() |
|
| 499 | 17 | ->end() |
|
| 500 | 17 | ->end() |
|
| 501 | 17 | ->arrayNode('model_to_elastica_transformer') |
|
| 502 | 17 | ->addDefaultsIfNotSet() |
|
| 503 | 17 | ->children() |
|
| 504 | 17 | ->scalarNode('service')->end() |
|
| 505 | 17 | ->end() |
|
| 506 | 17 | ->end() |
|
| 507 | 17 | ->arrayNode('persister') |
|
| 508 | 17 | ->addDefaultsIfNotSet() |
|
| 509 | 17 | ->children() |
|
| 510 | 17 | ->scalarNode('service')->end() |
|
| 511 | 17 | ->end() |
|
| 512 | 17 | ->end() |
|
| 513 | 17 | ->end(); |
|
| 514 | |||
| 515 | 17 | return $node; |
|
| 516 | } |
||
| 517 | |||
| 518 | /** |
||
| 519 | * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
||
| 520 | */ |
||
| 521 | 17 | protected function getSerializerNode() |
|
| 541 | } |
||
| 542 |
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.