Completed
Pull Request — master (#1151)
by Richard
05:35
created

Configuration   B

Complexity

Total Complexity 34

Size/Duplication

Total Lines 606
Duplicated Lines 10.23 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 34
c 2
b 0
f 0
lcom 1
cbo 6
dl 62
loc 606
ccs 390
cts 390
cp 1
rs 8.6792

17 Methods

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