Completed
Pull Request — master (#1075)
by Marcos
13:10 queued 10:41
created

Configuration   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 602
Duplicated Lines 10.3 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 98.73%

Importance

Changes 7
Bugs 0 Features 3
Metric Value
wmc 34
c 7
b 0
f 3
lcom 1
cbo 6
dl 62
loc 602
ccs 390
cts 395
cp 0.9873
rs 9.0196

17 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B getConfigTreeBuilder() 0 29 1
B addIndexesSection() 0 34 1
A getPropertiesNode() 0 12 1
B getDynamicTemplateNode() 0 27 1
A getIdNode() 13 13 1
A getSourceNode() 0 23 1
A getBoostNode() 0 14 1
A getRoutingNode() 14 14 1
A getParentNode() 0 15 1
A getAllNode() 0 15 1
A getTimestampNode() 17 17 1
A getTtlNode() 16 16 1
C getPersistenceNode() 2 92 7
A getSerializerNode() 0 20 1
B addClientsSection() 0 82 4
C getTypesNode() 0 92 9

How to fix   Duplicated Code   

Duplicated Code

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
2
3
namespace FOS\ElasticaBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
class Configuration implements ConfigurationInterface
10
{
11
    /**
12
     * Stores supported database drivers.
13
     *
14
     * @var array
15
     */
16
    private $supportedDrivers = array('orm', 'mongodb', 'propel', 'phpcr');
17
18
    /**
19
     * If the kernel is running in debug mode.
20
     *
21
     * @var bool
22
     */
23
    private $debug;
24
25 26
    public function __construct($debug)
26
    {
27 26
        $this->debug = $debug;
28 26
    }
29
30
    /**
31
     * Generates the configuration tree.
32
     *
33
     * @return TreeBuilder
34
     */
35 26
    public function getConfigTreeBuilder()
36
    {
37 26
        $treeBuilder = new TreeBuilder();
38 26
        $rootNode = $treeBuilder->root('fos_elastica', 'array');
39
40 26
        $this->addClientsSection($rootNode);
41 26
        $this->addIndexesSection($rootNode);
42
43
        $rootNode
44 26
            ->children()
45 26
                ->scalarNode('default_client')
46 26
                    ->info('Defaults to the first client defined')
47 26
                ->end()
48 26
                ->scalarNode('default_index')
49 26
                    ->info('Defaults to the first index defined')
50 26
                ->end()
51 26
                ->scalarNode('default_manager')->defaultValue('orm')->end()
52 26
                ->arrayNode('serializer')
53 26
                    ->treatNullLike(array())
54 26
                    ->children()
55 26
                        ->scalarNode('callback_class')->defaultValue('FOS\ElasticaBundle\Serializer\Callback')->end()
56 26
                        ->scalarNode('serializer')->defaultValue('serializer')->end()
57 26
                    ->end()
58 26
                ->end()
59 26
            ->end()
60
        ;
61
62 26
        return $treeBuilder;
63
    }
64
65
    /**
66
     * Adds the configuration for the "clients" key.
67
     */
68 26
    private function addClientsSection(ArrayNodeDefinition $rootNode)
69
    {
70
        $rootNode
71 26
            ->fixXmlConfig('client')
72 26
            ->children()
73 26
                ->arrayNode('clients')
74 26
                    ->useAttributeAsKey('id')
75 26
                    ->prototype('array')
76 26
                        ->performNoDeepMerging()
77
                        // BC - Renaming 'servers' node to 'connections'
78 26
                        ->beforeNormalization()
79
                        ->ifTrue(function ($v) { return isset($v['servers']); })
80
                        ->then(function ($v) {
81
                            $v['connections'] = $v['servers'];
82
                            unset($v['servers']);
83
84
                            return $v;
85 26
                        })
86 26
                        ->end()
87
                        // Elastica names its properties with camel case, support both
88 26
                        ->beforeNormalization()
89
                        ->ifTrue(function ($v) { return isset($v['connection_strategy']); })
90
                        ->then(function ($v) {
91 4
                            $v['connectionStrategy'] = $v['connection_strategy'];
92 4
                            unset($v['connection_strategy']);
93
94 4
                            return $v;
95 26
                        })
96 26
                        ->end()
97
                        // If there is no connections array key defined, assume a single connection.
98 26
                        ->beforeNormalization()
99
                        ->ifTrue(function ($v) { return is_array($v) && !array_key_exists('connections', $v); })
100
                        ->then(function ($v) {
101
                            return array(
102 25
                                'connections' => array($v),
103 25
                            );
104 26
                        })
105 26
                        ->end()
106 26
                        ->children()
107 26
                            ->arrayNode('connections')
108 26
                                ->requiresAtLeastOneElement()
109 26
                                ->prototype('array')
110 26
                                    ->fixXmlConfig('header')
111 26
                                    ->children()
112 26
                                        ->scalarNode('url')
113 26
                                            ->validate()
114
                                                ->ifTrue(function ($url) { return $url && substr($url, -1) !== '/'; })
115
                                                ->then(function ($url) { return $url.'/'; })
116 26
                                            ->end()
117 26
                                        ->end()
118 26
                                        ->scalarNode('host')->end()
119 26
                                        ->scalarNode('port')->end()
120 26
                                        ->scalarNode('proxy')->end()
121 26
                                        ->scalarNode('logger')
122 26
                                            ->defaultValue($this->debug ? 'fos_elastica.logger' : false)
123 26
                                            ->treatNullLike('fos_elastica.logger')
124 26
                                            ->treatTrueLike('fos_elastica.logger')
125 26
                                        ->end()
126 26
                                        ->booleanNode('compression')->defaultValue(false)->end()
127 26
                                        ->arrayNode('headers')
128 26
                                            ->useAttributeAsKey('name')
129 26
                                            ->prototype('scalar')->end()
130 26
                                        ->end()
131 26
                                        ->scalarNode('transport')->end()
132 26
                                        ->scalarNode('timeout')->end()
133 26
                                        ->scalarNode('connectTimeout')->end()
134 26
                                        ->scalarNode('retryOnConflict')
135 26
                                            ->defaultValue(0)
136 26
                                        ->end()
137 26
                                    ->end()
138 26
                                ->end()
139 26
                            ->end()
140 26
                            ->scalarNode('timeout')->end()
141 26
                            ->scalarNode('connectTimeout')->end()
142 26
                            ->scalarNode('headers')->end()
143 26
                            ->scalarNode('connectionStrategy')->defaultValue('Simple')->end()
144 26
                        ->end()
145 26
                    ->end()
146 26
                ->end()
147 26
            ->end()
148
        ;
149 26
    }
150
151
    /**
152
     * Adds the configuration for the "indexes" key.
153
     */
154 26
    private function addIndexesSection(ArrayNodeDefinition $rootNode)
155
    {
156
        $rootNode
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Config...\Builder\NodeDefinition as the method children() does only exist in the following sub-classes of Symfony\Component\Config...\Builder\NodeDefinition: Symfony\Component\Config...der\ArrayNodeDefinition. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
157 26
            ->fixXmlConfig('index')
158 26
            ->children()
159 26
                ->arrayNode('indexes')
160 26
                    ->useAttributeAsKey('name')
161 26
                    ->prototype('array')
162 26
                        ->children()
163 26
                            ->scalarNode('index_name')
164 26
                                ->info('Defaults to the name of the index, but can be modified if the index name is different in ElasticSearch')
165 26
                            ->end()
166 26
                            ->booleanNode('use_alias')->defaultValue(false)->end()
167 26
                            ->scalarNode('client')->end()
168 26
                            ->scalarNode('finder')
169 26
                                ->treatNullLike(true)
170 26
                                ->defaultFalse()
171 26
                            ->end()
172 26
                            ->arrayNode('type_prototype')
173 26
                                ->children()
174 26
                                    ->scalarNode('index_analyzer')->end()
175 26
                                    ->scalarNode('search_analyzer')->end()
176 26
                                    ->append($this->getPersistenceNode())
177 26
                                    ->append($this->getSerializerNode())
178 26
                                ->end()
179 26
                            ->end()
180 26
                            ->variableNode('settings')->defaultValue(array())->end()
181 26
                        ->end()
182 26
                        ->append($this->getTypesNode())
183 26
                    ->end()
184 26
                ->end()
185 26
            ->end()
186
        ;
187 26
    }
188
189
    /**
190
     * Returns the array node used for "types".
191
     */
192 26
    protected function getTypesNode()
193
    {
194 26
        $builder = new TreeBuilder();
195 26
        $node = $builder->root('types');
196
197
        $node
198 26
            ->useAttributeAsKey('name')
199 26
            ->prototype('array')
200 26
                ->treatNullLike(array())
201 26
                ->beforeNormalization()
202 26
                ->ifNull()
203 26
                ->thenEmptyArray()
204 26
                ->end()
205
                // BC - Renaming 'mappings' node to 'properties'
206 26
                ->beforeNormalization()
207
                ->ifTrue(function ($v) { return array_key_exists('mappings', $v); })
208
                ->then(function ($v) {
209 13
                    $v['properties'] = $v['mappings'];
210 13
                    unset($v['mappings']);
211
212 13
                    return $v;
213 26
                })
214 26
                ->end()
215
                // BC - Support the old is_indexable_callback property
216 26
                ->beforeNormalization()
217
                ->ifTrue(function ($v) {
218 18
                    return isset($v['persistence']) &&
219 18
                        isset($v['persistence']['listener']) &&
220 18
                        isset($v['persistence']['listener']['is_indexable_callback']);
221 26
                })
222
                ->then(function ($v) {
223 5
                    $callback = $v['persistence']['listener']['is_indexable_callback'];
224
225 5
                    if (is_array($callback)) {
226 5
                        list($class) = $callback + array(null);
227
228 5
                        if ($class[0] !== '@' && is_string($class) && !class_exists($class)) {
229
                            $callback[0] = '@'.$class;
230
                        }
231 5
                    }
232
233 5
                    $v['indexable_callback'] = $callback;
234 5
                    unset($v['persistence']['listener']['is_indexable_callback']);
235
236 5
                    return $v;
237 26
                })
238 26
                ->end()
239
                // Support multiple dynamic_template formats to match the old bundle style
240
                // and the way ElasticSearch expects them
241 26
                ->beforeNormalization()
242
                ->ifTrue(function ($v) { return isset($v['dynamic_templates']); })
243
                ->then(function ($v) {
244 4
                    $dt = array();
245 4
                    foreach ($v['dynamic_templates'] as $key => $type) {
246 4
                        if (is_int($key)) {
247 4
                            $dt[] = $type;
248 4
                        } else {
249 4
                            $dt[][$key] = $type;
250
                        }
251 4
                    }
252
253 4
                    $v['dynamic_templates'] = $dt;
254
255 4
                    return $v;
256 26
                })
257 26
                ->end()
258 26
                ->children()
259 26
                    ->booleanNode('date_detection')->end()
260 26
                    ->arrayNode('dynamic_date_formats')->prototype('scalar')->end()->end()
261 26
                    ->scalarNode('index_analyzer')->end()
262 26
                    ->booleanNode('numeric_detection')->end()
263 26
                    ->scalarNode('search_analyzer')->end()
264 26
                    ->scalarNode('dynamic')->end()
265 26
                    ->variableNode('indexable_callback')->end()
266 26
                    ->append($this->getPersistenceNode())
267 26
                    ->append($this->getSerializerNode())
268 26
                ->end()
269 26
                ->append($this->getIdNode())
270 26
                ->append($this->getPropertiesNode())
271 26
                ->append($this->getDynamicTemplateNode())
272 26
                ->append($this->getSourceNode())
273 26
                ->append($this->getBoostNode())
274 26
                ->append($this->getRoutingNode())
275 26
                ->append($this->getParentNode())
276 26
                ->append($this->getAllNode())
277 26
                ->append($this->getTimestampNode())
278 26
                ->append($this->getTtlNode())
279 26
            ->end()
280
        ;
281
282 26
        return $node;
283
    }
284
285
    /**
286
     * Returns the array node used for "properties".
287
     */
288 26
    protected function getPropertiesNode()
289
    {
290 26
        $builder = new TreeBuilder();
291 26
        $node = $builder->root('properties');
292
293
        $node
294 26
            ->useAttributeAsKey('name')
295 26
            ->prototype('variable')
296 26
                ->treatNullLike(array());
297
298 26
        return $node;
299
    }
300
301
    /**
302
     * Returns the array node used for "dynamic_templates".
303
     */
304 26
    public function getDynamicTemplateNode()
305
    {
306 26
        $builder = new TreeBuilder();
307 26
        $node = $builder->root('dynamic_templates');
308
309
        $node
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Config...\Builder\NodeDefinition as the method prototype() does only exist in the following sub-classes of Symfony\Component\Config...\Builder\NodeDefinition: Symfony\Component\Config...der\ArrayNodeDefinition. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
310 26
            ->prototype('array')
311 26
                ->prototype('array')
312 26
                    ->children()
313 26
                        ->scalarNode('match')->end()
314 26
                        ->scalarNode('unmatch')->end()
315 26
                        ->scalarNode('match_mapping_type')->end()
316 26
                        ->scalarNode('path_match')->end()
317 26
                        ->scalarNode('path_unmatch')->end()
318 26
                        ->scalarNode('match_pattern')->end()
319 26
                        ->arrayNode('mapping')
320 26
                            ->prototype('variable')
321 26
                                ->treatNullLike(array())
322 26
                            ->end()
323 26
                        ->end()
324 26
                    ->end()
325 26
                ->end()
326 26
            ->end()
327
        ;
328
329 26
        return $node;
330
    }
331
332
    /**
333
     * Returns the array node used for "_id".
334
     */
335 26 View Code Duplication
    protected function getIdNode()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
336
    {
337 26
        $builder = new TreeBuilder();
338 26
        $node = $builder->root('_id');
339
340
        $node
341 26
            ->children()
342 26
            ->scalarNode('path')->end()
343 26
            ->end()
344
        ;
345
346 26
        return $node;
347
    }
348
349
    /**
350
     * Returns the array node used for "_source".
351
     */
352 26
    protected function getSourceNode()
353
    {
354 26
        $builder = new TreeBuilder();
355 26
        $node = $builder->root('_source');
356
357
        $node
358 26
            ->children()
359 26
                ->arrayNode('excludes')
360 26
                    ->useAttributeAsKey('name')
361 26
                    ->prototype('scalar')->end()
362 26
                ->end()
363 26
                ->arrayNode('includes')
364 26
                    ->useAttributeAsKey('name')
365 26
                    ->prototype('scalar')->end()
366 26
                ->end()
367 26
                ->scalarNode('compress')->end()
368 26
                ->scalarNode('compress_threshold')->end()
369 26
                ->scalarNode('enabled')->defaultTrue()->end()
370 26
            ->end()
371
        ;
372
373 26
        return $node;
374
    }
375
376
    /**
377
     * Returns the array node used for "_boost".
378
     */
379 26
    protected function getBoostNode()
380
    {
381 26
        $builder = new TreeBuilder();
382 26
        $node = $builder->root('_boost');
383
384
        $node
385 26
            ->children()
386 26
                ->scalarNode('name')->end()
387 26
                ->scalarNode('null_value')->end()
388 26
            ->end()
389
        ;
390
391 26
        return $node;
392
    }
393
394
    /**
395
     * Returns the array node used for "_routing".
396
     */
397 26 View Code Duplication
    protected function getRoutingNode()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
398
    {
399 26
        $builder = new TreeBuilder();
400 26
        $node = $builder->root('_routing');
401
402
        $node
403 26
            ->children()
404 26
                ->scalarNode('required')->end()
405 26
                ->scalarNode('path')->end()
406 26
            ->end()
407
        ;
408
409 26
        return $node;
410
    }
411
412
    /**
413
     * Returns the array node used for "_parent".
414
     */
415 26
    protected function getParentNode()
416
    {
417 26
        $builder = new TreeBuilder();
418 26
        $node = $builder->root('_parent');
419
420
        $node
421 26
            ->children()
422 26
                ->scalarNode('type')->end()
423 26
                ->scalarNode('property')->defaultValue(null)->end()
424 26
                ->scalarNode('identifier')->defaultValue('id')->end()
425 26
            ->end()
426
        ;
427
428 26
        return $node;
429
    }
430
431
    /**
432
     * Returns the array node used for "_all".
433
     */
434 26
    protected function getAllNode()
435
    {
436 26
        $builder = new TreeBuilder();
437 26
        $node = $builder->root('_all');
438
439
        $node
440 26
            ->children()
441 26
            ->scalarNode('enabled')->defaultValue(true)->end()
442 26
            ->scalarNode('index_analyzer')->end()
443 26
            ->scalarNode('search_analyzer')->end()
444 26
            ->end()
445
        ;
446
447 26
        return $node;
448
    }
449
450
    /**
451
     * Returns the array node used for "_timestamp".
452
     */
453 26 View Code Duplication
    protected function getTimestampNode()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
454
    {
455 26
        $builder = new TreeBuilder();
456 26
        $node = $builder->root('_timestamp');
457
458
        $node
459 26
            ->children()
460 26
            ->scalarNode('enabled')->defaultValue(true)->end()
461 26
            ->scalarNode('path')->end()
462 26
            ->scalarNode('format')->end()
463 26
            ->scalarNode('store')->end()
464 26
            ->scalarNode('index')->end()
465 26
            ->end()
466
        ;
467
468 26
        return $node;
469
    }
470
471
    /**
472
     * Returns the array node used for "_ttl".
473
     */
474 26 View Code Duplication
    protected function getTtlNode()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
475
    {
476 26
        $builder = new TreeBuilder();
477 26
        $node = $builder->root('_ttl');
478
479
        $node
480 26
            ->children()
481 26
            ->scalarNode('enabled')->defaultValue(true)->end()
482 26
            ->scalarNode('default')->end()
483 26
            ->scalarNode('store')->end()
484 26
            ->scalarNode('index')->end()
485 26
            ->end()
486
        ;
487
488 26
        return $node;
489
    }
490
491
    /**
492
     * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition
493
     */
494 26
    protected function getPersistenceNode()
495
    {
496 26
        $builder = new TreeBuilder();
497 26
        $node = $builder->root('persistence');
498
499
        $node
500 26
            ->validate()
501 View Code Duplication
                ->ifTrue(function ($v) { return isset($v['driver']) && 'propel' === $v['driver'] && isset($v['listener']); })
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
502 26
                    ->thenInvalid('Propel doesn\'t support listeners')
503 View Code Duplication
                ->ifTrue(function ($v) { return isset($v['driver']) && 'propel' === $v['driver'] && isset($v['repository']); })
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
504 26
                    ->thenInvalid('Propel doesn\'t support the "repository" parameter')
505
                ->ifTrue(function($v) { return isset($v['driver']) && 'orm' !== $v['driver'] && !empty($v['elastica_to_model_transformer']['hints']); })
506 26
                    ->thenInvalid('Hints are only supported by the "orm" driver')
507 26
            ->end()
508 26
            ->children()
509 26
                ->scalarNode('driver')
510 26
                    ->validate()
511 26
                    ->ifNotInArray($this->supportedDrivers)
512 26
                        ->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($this->supportedDrivers))
513 26
                    ->end()
514 26
                ->end()
515 26
                ->scalarNode('model')->end()
516 26
                ->scalarNode('repository')->end()
517 26
                ->scalarNode('identifier')->defaultValue('id')->end()
518 26
                ->arrayNode('provider')
519 26
                    ->children()
520 26
                        ->scalarNode('batch_size')->defaultValue(100)->end()
521 26
                        ->scalarNode('clear_object_manager')->defaultTrue()->end()
522 26
                        ->scalarNode('debug_logging')
523 26
                            ->defaultValue($this->debug)
524 26
                            ->treatNullLike(true)
525 26
                        ->end()
526 26
                        ->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end()
527 26
                        ->scalarNode('service')->end()
528 26
                    ->end()
529 26
                ->end()
530 26
                ->arrayNode('listener')
531 26
                    ->children()
532 26
                        ->scalarNode('insert')->defaultTrue()->end()
533 26
                        ->scalarNode('update')->defaultTrue()->end()
534 26
                        ->scalarNode('delete')->defaultTrue()->end()
535 26
                        ->scalarNode('flush')->defaultTrue()->end()
536 26
                        ->booleanNode('immediate')->defaultFalse()->end()
537 26
                        ->scalarNode('logger')
538 26
                            ->defaultFalse()
539 26
                            ->treatNullLike('fos_elastica.logger')
540 26
                            ->treatTrueLike('fos_elastica.logger')
541 26
                        ->end()
542 26
                        ->scalarNode('service')->end()
543 26
                    ->end()
544 26
                ->end()
545 26
                ->arrayNode('finder')
546 26
                    ->children()
547 26
                        ->scalarNode('service')->end()
548 26
                    ->end()
549 26
                ->end()
550 26
                ->arrayNode('elastica_to_model_transformer')
551 26
                    ->addDefaultsIfNotSet()
552 26
                    ->children()
553 26
                        ->arrayNode('hints')
554 26
                            ->prototype('array')
555 26
                                ->children()
556 26
                                    ->scalarNode('name')->end()
557 26
                                    ->scalarNode('value')->end()
558 26
                                ->end()
559 26
                            ->end()
560 26
                        ->end()
561 26
                        ->booleanNode('hydrate')->defaultTrue()->end()
562 26
                        ->booleanNode('ignore_missing')
563 26
                            ->defaultFalse()
564 26
                            ->info('Silently ignore results returned from Elasticsearch without corresponding persistent object.')
565 26
                        ->end()
566 26
                        ->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end()
567 26
                        ->scalarNode('service')->end()
568 26
                    ->end()
569 26
                ->end()
570 26
                ->arrayNode('model_to_elastica_transformer')
571 26
                    ->addDefaultsIfNotSet()
572 26
                    ->children()
573 26
                        ->scalarNode('service')->end()
574 26
                    ->end()
575 26
                ->end()
576 26
                ->arrayNode('persister')
577 26
                    ->addDefaultsIfNotSet()
578 26
                    ->children()
579 26
                        ->scalarNode('service')->end()
580 26
                    ->end()
581 26
                ->end()
582 26
            ->end();
583
584 26
        return $node;
585
    }
586
587
    /**
588
     * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition
589
     */
590 26
    protected function getSerializerNode()
591
    {
592 26
        $builder = new TreeBuilder();
593 26
        $node = $builder->root('serializer');
594
595
        $node
596 26
            ->addDefaultsIfNotSet()
597 26
            ->children()
598 26
                ->arrayNode('groups')
599 26
                    ->treatNullLike(array())
600 26
                    ->prototype('scalar')->end()
601 26
                ->end()
602 26
                ->scalarNode('version')->end()
603 26
                ->booleanNode('serialize_null')
604 26
                    ->defaultFalse()
605 26
                ->end()
606 26
            ->end();
607
608 26
        return $node;
609
    }
610
}
611