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 | 24 | public function __construct($debug) |
|
38 | |||
39 | /** |
||
40 | * Generates the configuration tree. |
||
41 | * |
||
42 | * @return TreeBuilder |
||
43 | */ |
||
44 | 24 | public function getConfigTreeBuilder() |
|
73 | |||
74 | /** |
||
75 | * Returns the array node used for "dynamic_templates". |
||
76 | */ |
||
77 | 24 | public function getDynamicTemplateNode() |
|
104 | |||
105 | /** |
||
106 | * Returns the array node used for "types". |
||
107 | */ |
||
108 | 24 | protected function getTypesNode() |
|
109 | { |
||
110 | 24 | $builder = new TreeBuilder(); |
|
111 | 24 | $node = $builder->root('types'); |
|
112 | |||
113 | $node |
||
114 | 24 | ->useAttributeAsKey('name') |
|
115 | 24 | ->prototype('array') |
|
116 | 24 | ->treatNullLike([]) |
|
117 | 24 | ->beforeNormalization() |
|
118 | 24 | ->ifNull() |
|
119 | 24 | ->thenEmptyArray() |
|
120 | 24 | ->end() |
|
121 | // Support multiple dynamic_template formats to match the old bundle style |
||
122 | // and the way ElasticSearch expects them |
||
123 | 24 | ->beforeNormalization() |
|
124 | 24 | ->ifTrue(function ($v) { |
|
125 | 15 | return isset($v['dynamic_templates']); |
|
126 | 24 | }) |
|
127 | 24 | ->then(function ($v) { |
|
128 | 1 | $dt = []; |
|
129 | 1 | foreach ($v['dynamic_templates'] as $key => $type) { |
|
130 | 1 | if (is_int($key)) { |
|
131 | 1 | $dt[] = $type; |
|
132 | } else { |
||
133 | 1 | $dt[][$key] = $type; |
|
134 | } |
||
135 | } |
||
136 | |||
137 | 1 | $v['dynamic_templates'] = $dt; |
|
138 | |||
139 | 1 | return $v; |
|
140 | 24 | }) |
|
141 | 24 | ->end() |
|
142 | 24 | ->children() |
|
143 | 24 | ->booleanNode('date_detection')->end() |
|
144 | 24 | ->arrayNode('dynamic_date_formats')->prototype('scalar')->end()->end() |
|
145 | 24 | ->scalarNode('analyzer')->end() |
|
146 | 24 | ->booleanNode('numeric_detection')->end() |
|
147 | 24 | ->scalarNode('dynamic')->end() |
|
148 | 24 | ->variableNode('indexable_callback')->end() |
|
149 | 24 | ->append($this->getPersistenceNode()) |
|
150 | 24 | ->append($this->getSerializerNode()) |
|
151 | 24 | ->end() |
|
152 | 24 | ->append($this->getIdNode()) |
|
153 | 24 | ->append($this->getPropertiesNode()) |
|
154 | 24 | ->append($this->getDynamicTemplateNode()) |
|
155 | 24 | ->append($this->getSourceNode()) |
|
156 | 24 | ->append($this->getRoutingNode()) |
|
157 | 24 | ->append($this->getParentNode()) |
|
158 | 24 | ->append($this->getAllNode()) |
|
159 | 24 | ->end() |
|
160 | ; |
||
161 | |||
162 | 24 | return $node; |
|
163 | } |
||
164 | |||
165 | /** |
||
166 | * Returns the array node used for "properties". |
||
167 | */ |
||
168 | 24 | protected function getPropertiesNode() |
|
180 | |||
181 | /** |
||
182 | * Returns the array node used for "_id". |
||
183 | */ |
||
184 | 24 | View Code Duplication | protected function getIdNode() |
197 | |||
198 | /** |
||
199 | * Returns the array node used for "_source". |
||
200 | */ |
||
201 | 24 | protected function getSourceNode() |
|
224 | |||
225 | /** |
||
226 | * Returns the array node used for "_routing". |
||
227 | */ |
||
228 | 24 | View Code Duplication | protected function getRoutingNode() |
229 | { |
||
230 | 24 | $builder = new TreeBuilder(); |
|
231 | 24 | $node = $builder->root('_routing'); |
|
232 | |||
233 | $node |
||
234 | 24 | ->children() |
|
235 | 24 | ->scalarNode('required')->end() |
|
236 | 24 | ->scalarNode('path')->end() |
|
237 | 24 | ->end() |
|
238 | ; |
||
239 | |||
240 | 24 | return $node; |
|
241 | } |
||
242 | |||
243 | /** |
||
244 | * Returns the array node used for "_parent". |
||
245 | */ |
||
246 | 24 | protected function getParentNode() |
|
261 | |||
262 | /** |
||
263 | * Returns the array node used for "_all". |
||
264 | */ |
||
265 | 24 | protected function getAllNode() |
|
279 | |||
280 | /** |
||
281 | * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
||
282 | */ |
||
283 | 24 | protected function getPersistenceNode() |
|
385 | |||
386 | /** |
||
387 | * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
||
388 | */ |
||
389 | 24 | protected function getSerializerNode() |
|
409 | |||
410 | /** |
||
411 | * Adds the configuration for the "clients" key. |
||
412 | */ |
||
413 | 24 | private function addClientsSection(ArrayNodeDefinition $rootNode) |
|
414 | { |
||
415 | $rootNode |
||
416 | 24 | ->fixXmlConfig('client') |
|
417 | 24 | ->children() |
|
418 | 24 | ->arrayNode('clients') |
|
419 | 24 | ->useAttributeAsKey('id') |
|
420 | 24 | ->prototype('array') |
|
421 | 24 | ->performNoDeepMerging() |
|
422 | // Elastica names its properties with camel case, support both |
||
423 | 24 | ->beforeNormalization() |
|
424 | 24 | ->ifTrue(function ($v) { |
|
425 | 23 | return isset($v['connection_strategy']); |
|
426 | 24 | }) |
|
427 | 24 | ->then(function ($v) { |
|
428 | 1 | $v['connectionStrategy'] = $v['connection_strategy']; |
|
429 | 1 | unset($v['connection_strategy']); |
|
430 | |||
431 | 1 | return $v; |
|
432 | 24 | }) |
|
433 | 24 | ->end() |
|
434 | // If there is no connections array key defined, assume a single connection. |
||
435 | 24 | ->beforeNormalization() |
|
436 | 24 | ->ifTrue(function ($v) { |
|
437 | 23 | return is_array($v) && !array_key_exists('connections', $v); |
|
438 | 24 | }) |
|
439 | 24 | ->then(function ($v) { |
|
440 | return [ |
||
441 | 23 | 'connections' => [$v], |
|
442 | ]; |
||
443 | 24 | }) |
|
444 | 24 | ->end() |
|
445 | 24 | ->children() |
|
446 | 24 | ->arrayNode('connections') |
|
447 | 24 | ->requiresAtLeastOneElement() |
|
448 | 24 | ->prototype('array') |
|
449 | 24 | ->fixXmlConfig('header') |
|
450 | 24 | ->children() |
|
451 | 24 | ->scalarNode('url') |
|
452 | 24 | ->validate() |
|
453 | 24 | ->ifTrue(function ($url) { |
|
454 | 12 | return $url && '/' !== substr($url, -1); |
|
455 | 24 | }) |
|
456 | 24 | ->then(function ($url) { |
|
457 | 12 | return $url.'/'; |
|
458 | 24 | }) |
|
459 | 24 | ->end() |
|
460 | 24 | ->end() |
|
461 | 24 | ->scalarNode('username')->end() |
|
462 | 24 | ->scalarNode('password')->end() |
|
463 | 24 | ->scalarNode('host')->end() |
|
464 | 24 | ->scalarNode('port')->end() |
|
465 | 24 | ->scalarNode('proxy')->end() |
|
466 | 24 | ->scalarNode('aws_access_key_id')->end() |
|
467 | 24 | ->scalarNode('aws_secret_access_key')->end() |
|
468 | 24 | ->scalarNode('aws_region')->end() |
|
469 | 24 | ->scalarNode('aws_session_token')->end() |
|
470 | 24 | ->booleanNode('ssl')->defaultValue(false)->end() |
|
471 | 24 | ->scalarNode('logger') |
|
472 | 24 | ->defaultValue($this->debug ? 'fos_elastica.logger' : false) |
|
473 | 24 | ->treatNullLike('fos_elastica.logger') |
|
474 | 24 | ->treatTrueLike('fos_elastica.logger') |
|
475 | 24 | ->end() |
|
476 | 24 | ->booleanNode('compression')->defaultValue(false)->end() |
|
477 | 24 | ->arrayNode('headers') |
|
478 | 24 | ->normalizeKeys(false) |
|
479 | 24 | ->useAttributeAsKey('name') |
|
480 | 24 | ->prototype('scalar')->end() |
|
481 | 24 | ->end() |
|
482 | 24 | ->arrayNode('curl') |
|
483 | 24 | ->useAttributeAsKey(CURLOPT_SSL_VERIFYPEER) |
|
484 | 24 | ->prototype('boolean')->end() |
|
485 | 24 | ->end() |
|
486 | 24 | ->scalarNode('transport')->end() |
|
487 | 24 | ->scalarNode('timeout')->end() |
|
488 | 24 | ->scalarNode('connectTimeout')->end() |
|
489 | 24 | ->scalarNode('retryOnConflict') |
|
490 | 24 | ->defaultValue(0) |
|
491 | 24 | ->end() |
|
492 | 24 | ->end() |
|
493 | 24 | ->end() |
|
494 | 24 | ->end() |
|
495 | 24 | ->scalarNode('timeout')->end() |
|
496 | 24 | ->scalarNode('connectTimeout')->end() |
|
497 | 24 | ->scalarNode('headers')->end() |
|
498 | 24 | ->scalarNode('connectionStrategy')->defaultValue('Simple')->end() |
|
499 | 24 | ->end() |
|
500 | 24 | ->end() |
|
501 | 24 | ->end() |
|
502 | 24 | ->end() |
|
503 | ; |
||
504 | 24 | } |
|
505 | |||
506 | /** |
||
507 | * Adds the configuration for the "indexes" key. |
||
508 | */ |
||
509 | 24 | 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.