Completed
Pull Request — master (#1069)
by Giovanni
11:08
created

Configuration   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 600
Duplicated Lines 10.33 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 98.74%

Importance

Changes 9
Bugs 0 Features 3
Metric Value
wmc 34
c 9
b 0
f 3
lcom 1
cbo 6
dl 62
loc 600
ccs 391
cts 396
cp 0.9874
rs 9.2

17 Methods

Rating   Name   Duplication   Size   Complexity  
B addIndexesSection() 0 33 1
A getParentNode() 0 13 1
A getAllNode() 0 14 1
B addClientsSection() 0 82 4
C getTypesNode() 0 91 9
A __construct() 0 4 1
B getConfigTreeBuilder() 0 29 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 getTimestampNode() 17 17 1
A getTtlNode() 16 16 1
C getPersistenceNode() 2 95 7
A getSerializerNode() 0 20 1

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('analyzer')->end()
175 26
                                    ->append($this->getPersistenceNode())
176 26
                                    ->append($this->getSerializerNode())
177 26
                                ->end()
178 26
                            ->end()
179 26
                            ->variableNode('settings')->defaultValue(array())->end()
180 26
                        ->end()
181 26
                        ->append($this->getTypesNode())
182 26
                    ->end()
183 26
                ->end()
184 26
            ->end()
185 26
        ;
186
    }
187 26
188
    /**
189
     * Returns the array node used for "types".
190
     */
191
    protected function getTypesNode()
192 26
    {
193
        $builder = new TreeBuilder();
194 26
        $node = $builder->root('types');
195 26
196
        $node
197
            ->useAttributeAsKey('name')
198 26
            ->prototype('array')
199 26
                ->treatNullLike(array())
200 26
                ->beforeNormalization()
201 26
                ->ifNull()
202 26
                ->thenEmptyArray()
203 26
                ->end()
204 26
                // BC - Renaming 'mappings' node to 'properties'
205
                ->beforeNormalization()
206 26
                ->ifTrue(function ($v) { return array_key_exists('mappings', $v); })
207
                ->then(function ($v) {
208
                    $v['properties'] = $v['mappings'];
209 13
                    unset($v['mappings']);
210 13
211
                    return $v;
212 13
                })
213 26
                ->end()
214 26
                // BC - Support the old is_indexable_callback property
215
                ->beforeNormalization()
216 26
                ->ifTrue(function ($v) {
217
                    return isset($v['persistence']) &&
218 18
                        isset($v['persistence']['listener']) &&
219 18
                        isset($v['persistence']['listener']['is_indexable_callback']);
220 18
                })
221 26
                ->then(function ($v) {
222
                    $callback = $v['persistence']['listener']['is_indexable_callback'];
223 5
224
                    if (is_array($callback)) {
225 5
                        list($class) = $callback + array(null);
226 5
227
                        if ($class[0] !== '@' && is_string($class) && !class_exists($class)) {
228 5
                            $callback[0] = '@'.$class;
229
                        }
230
                    }
231 5
232
                    $v['indexable_callback'] = $callback;
233 5
                    unset($v['persistence']['listener']['is_indexable_callback']);
234 5
235
                    return $v;
236 5
                })
237 26
                ->end()
238 26
                // Support multiple dynamic_template formats to match the old bundle style
239
                // and the way ElasticSearch expects them
240
                ->beforeNormalization()
241 26
                ->ifTrue(function ($v) { return isset($v['dynamic_templates']); })
242
                ->then(function ($v) {
243
                    $dt = array();
244 4
                    foreach ($v['dynamic_templates'] as $key => $type) {
245 4
                        if (is_int($key)) {
246 4
                            $dt[] = $type;
247 4
                        } else {
248 4
                            $dt[][$key] = $type;
249 4
                        }
250
                    }
251 4
252
                    $v['dynamic_templates'] = $dt;
253 4
254
                    return $v;
255 4
                })
256 26
                ->end()
257 26
                ->children()
258 26
                    ->booleanNode('date_detection')->end()
259 26
                    ->arrayNode('dynamic_date_formats')->prototype('scalar')->end()->end()
260 26
                    ->scalarNode('analyzer')->end()
261 26
                    ->booleanNode('numeric_detection')->end()
262 26
                    ->scalarNode('dynamic')->end()
263 26
                    ->variableNode('indexable_callback')->end()
264 26
                    ->append($this->getPersistenceNode())
265 26
                    ->append($this->getSerializerNode())
266 26
                ->end()
267 26
                ->append($this->getIdNode())
268 26
                ->append($this->getPropertiesNode())
269 26
                ->append($this->getDynamicTemplateNode())
270 26
                ->append($this->getSourceNode())
271 26
                ->append($this->getBoostNode())
272 26
                ->append($this->getRoutingNode())
273 26
                ->append($this->getParentNode())
274 26
                ->append($this->getAllNode())
275 26
                ->append($this->getTimestampNode())
276 26
                ->append($this->getTtlNode())
277 26
            ->end()
278 26
        ;
279 26
280
        return $node;
281
    }
282 26
283
    /**
284
     * Returns the array node used for "properties".
285
     */
286
    protected function getPropertiesNode()
287
    {
288 26
        $builder = new TreeBuilder();
289
        $node = $builder->root('properties');
290 26
291 26
        $node
292
            ->useAttributeAsKey('name')
293
            ->prototype('variable')
294 26
                ->treatNullLike(array());
295 26
296 26
        return $node;
297
    }
298 26
299
    /**
300
     * Returns the array node used for "dynamic_templates".
301
     */
302
    public function getDynamicTemplateNode()
303
    {
304 26
        $builder = new TreeBuilder();
305
        $node = $builder->root('dynamic_templates');
306 26
307 26
        $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...
308
            ->prototype('array')
309
                ->prototype('array')
310 26
                    ->children()
311 26
                        ->scalarNode('match')->end()
312 26
                        ->scalarNode('unmatch')->end()
313 26
                        ->scalarNode('match_mapping_type')->end()
314 26
                        ->scalarNode('path_match')->end()
315 26
                        ->scalarNode('path_unmatch')->end()
316 26
                        ->scalarNode('match_pattern')->end()
317 26
                        ->arrayNode('mapping')
318 26
                            ->prototype('variable')
319 26
                                ->treatNullLike(array())
320 26
                            ->end()
321 26
                        ->end()
322 26
                    ->end()
323 26
                ->end()
324 26
            ->end()
325 26
        ;
326 26
327
        return $node;
328
    }
329 26
330
    /**
331
     * Returns the array node used for "_id".
332
     */
333 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...
334
    {
335 26
        $builder = new TreeBuilder();
336
        $node = $builder->root('_id');
337 26
338 26
        $node
339
            ->children()
340
            ->scalarNode('path')->end()
341 26
            ->end()
342 26
        ;
343 26
344
        return $node;
345
    }
346 26
347
    /**
348
     * Returns the array node used for "_source".
349
     */
350
    protected function getSourceNode()
351
    {
352 26
        $builder = new TreeBuilder();
353
        $node = $builder->root('_source');
354 26
355 26
        $node
356
            ->children()
357
                ->arrayNode('excludes')
358 26
                    ->useAttributeAsKey('name')
359 26
                    ->prototype('scalar')->end()
360 26
                ->end()
361 26
                ->arrayNode('includes')
362 26
                    ->useAttributeAsKey('name')
363 26
                    ->prototype('scalar')->end()
364 26
                ->end()
365 26
                ->scalarNode('compress')->end()
366 26
                ->scalarNode('compress_threshold')->end()
367 26
                ->scalarNode('enabled')->defaultTrue()->end()
368 26
            ->end()
369 26
        ;
370 26
371
        return $node;
372
    }
373 26
374
    /**
375
     * Returns the array node used for "_boost".
376
     */
377
    protected function getBoostNode()
378
    {
379 26
        $builder = new TreeBuilder();
380
        $node = $builder->root('_boost');
381 26
382 26
        $node
383
            ->children()
384
                ->scalarNode('name')->end()
385 26
                ->scalarNode('null_value')->end()
386 26
            ->end()
387 26
        ;
388 26
389
        return $node;
390
    }
391 26
392
    /**
393
     * Returns the array node used for "_routing".
394
     */
395 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...
396
    {
397 26
        $builder = new TreeBuilder();
398
        $node = $builder->root('_routing');
399 26
400 26
        $node
401
            ->children()
402
                ->scalarNode('required')->end()
403 26
                ->scalarNode('path')->end()
404 26
            ->end()
405 26
        ;
406 26
407
        return $node;
408
    }
409 26
410
    /**
411
     * Returns the array node used for "_parent".
412
     */
413
    protected function getParentNode()
414
    {
415 26
        $builder = new TreeBuilder();
416
        $node = $builder->root('_parent');
417 26
418 26
        $node
419
            ->children()
420
                ->scalarNode('type')->end()
421 26
            ->end()
422 26
        ;
423 26
424 26
        return $node;
425 26
    }
426
427
    /**
428 26
     * Returns the array node used for "_all".
429
     */
430
    protected function getAllNode()
431
    {
432
        $builder = new TreeBuilder();
433
        $node = $builder->root('_all');
434 26
435
        $node
436 26
            ->children()
437 26
            ->scalarNode('enabled')->defaultValue(true)->end()
438
            ->scalarNode('analyzer')->end()
439
            ->end()
440 26
        ;
441 26
442 26
        return $node;
443 26
    }
444 26
445
    /**
446
     * Returns the array node used for "_timestamp".
447 26
     */
448 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...
449
    {
450
        $builder = new TreeBuilder();
451
        $node = $builder->root('_timestamp');
452
453 26
        $node
454
            ->children()
455 26
            ->scalarNode('enabled')->defaultValue(true)->end()
456 26
            ->scalarNode('path')->end()
457
            ->scalarNode('format')->end()
458
            ->scalarNode('store')->end()
459 26
            ->scalarNode('index')->end()
460 26
            ->end()
461 26
        ;
462 26
463 26
        return $node;
464 26
    }
465 26
466
    /**
467
     * Returns the array node used for "_ttl".
468 26
     */
469 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...
470
    {
471
        $builder = new TreeBuilder();
472
        $node = $builder->root('_ttl');
473
474 26
        $node
475
            ->children()
476 26
            ->scalarNode('enabled')->defaultValue(true)->end()
477 26
            ->scalarNode('default')->end()
478
            ->scalarNode('store')->end()
479
            ->scalarNode('index')->end()
480 26
            ->end()
481 26
        ;
482 26
483 26
        return $node;
484 26
    }
485 26
486
    /**
487
     * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition
488 26
     */
489
    protected function getPersistenceNode()
490
    {
491
        $builder = new TreeBuilder();
492
        $node = $builder->root('persistence');
493
494 26
        $node
495
            ->validate()
496 26 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...
497 26
                    ->thenInvalid('Propel doesn\'t support listeners')
498 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...
499
                    ->thenInvalid('Propel doesn\'t support the "repository" parameter')
500 26
                ->ifTrue(function($v) { return isset($v['driver']) && 'orm' !== $v['driver'] && !empty($v['elastica_to_model_transformer']['hints']); })
501
                    ->thenInvalid('Hints are only supported by the "orm" driver')
502 26
            ->end()
503
            ->children()
504 26
                ->scalarNode('driver')
505
                    ->defaultValue('orm')
506 26
                    ->validate()
507 26
                    ->ifNotInArray($this->supportedDrivers)
508 26
                        ->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($this->supportedDrivers))
509 26
                    ->end()
510 26
                ->end()
511 26
                ->scalarNode('model')->defaultValue(null)->end()
512 26
                ->scalarNode('repository')->end()
513 26
                ->scalarNode('identifier')->defaultValue('id')->end()
514 26
                ->arrayNode('provider')
515 26
                    ->addDefaultsIfNotSet()
516 26
                    ->children()
517 26
                        ->scalarNode('batch_size')->defaultValue(100)->end()
518 26
                        ->scalarNode('clear_object_manager')->defaultTrue()->end()
519 26
                        ->scalarNode('debug_logging')
520 26
                            ->defaultValue($this->debug)
521 26
                            ->treatNullLike(true)
522 26
                        ->end()
523 26
                        ->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end()
524 26
                        ->scalarNode('service')->end()
525 26
                    ->end()
526 26
                ->end()
527 26
                ->arrayNode('listener')
528 26
                    ->addDefaultsIfNotSet()
529 26
                    ->children()
530 26
                        ->scalarNode('insert')->defaultTrue()->end()
531 26
                        ->scalarNode('update')->defaultTrue()->end()
532 26
                        ->scalarNode('delete')->defaultTrue()->end()
533 26
                        ->scalarNode('flush')->defaultTrue()->end()
534 26
                        ->scalarNode('logger')
535 26
                            ->defaultFalse()
536 26
                            ->treatNullLike('fos_elastica.logger')
537 26
                            ->treatTrueLike('fos_elastica.logger')
538 26
                        ->end()
539 26
                        ->scalarNode('service')->end()
540 26
                    ->end()
541 26
                ->end()
542 26
                ->arrayNode('finder')
543 26
                    ->addDefaultsIfNotSet()
544 26
                    ->children()
545 26
                        ->scalarNode('service')->end()
546 26
                    ->end()
547 26
                ->end()
548 26
                ->arrayNode('elastica_to_model_transformer')
549 26
                    ->addDefaultsIfNotSet()
550 26
                    ->children()
551 26
                        ->arrayNode('hints')
552 26
                            ->prototype('array')
553 26
                                ->children()
554 26
                                    ->scalarNode('name')->end()
555 26
                                    ->scalarNode('value')->end()
556 26
                                ->end()
557 26
                            ->end()
558 26
                        ->end()
559 26
                        ->booleanNode('hydrate')->defaultTrue()->end()
560 26
                        ->booleanNode('ignore_missing')
561 26
                            ->defaultFalse()
562 26
                            ->info('Silently ignore results returned from Elasticsearch without corresponding persistent object.')
563 26
                        ->end()
564 26
                        ->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end()
565 26
                        ->scalarNode('service')->end()
566 26
                    ->end()
567 26
                ->end()
568 26
                ->arrayNode('model_to_elastica_transformer')
569 26
                    ->addDefaultsIfNotSet()
570 26
                    ->children()
571 26
                        ->scalarNode('service')->end()
572 26
                    ->end()
573 26
                ->end()
574 26
                ->arrayNode('persister')
575 26
                    ->addDefaultsIfNotSet()
576 26
                    ->children()
577 26
                        ->scalarNode('service')->end()
578 26
                    ->end()
579 26
                ->end()
580 26
            ->end();
581 26
582 26
        return $node;
583 26
    }
584 26
585 26
    /**
586
     * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition
587 26
     */
588
    protected function getSerializerNode()
589
    {
590
        $builder = new TreeBuilder();
591
        $node = $builder->root('serializer');
592
593 26
        $node
594
            ->addDefaultsIfNotSet()
595 26
            ->children()
596 26
                ->arrayNode('groups')
597
                    ->treatNullLike(array())
598
                    ->prototype('scalar')->end()
599 26
                ->end()
600 26
                ->scalarNode('version')->end()
601 26
                ->booleanNode('serialize_null')
602 26
                    ->defaultFalse()
603 26
                ->end()
604 26
            ->end();
605 26
606 26
        return $node;
607 26
    }
608
}
609