Completed
Pull Request — master (#1151)
by Richard
05:24
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 1
Bugs 0 Features 0
Metric Value
wmc 34
c 1
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 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
B addClientsSection() 0 86 4

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 27
    public function __construct($debug)
26
    {
27 27
        $this->debug = $debug;
28 27
    }
29
30
    /**
31
     * Generates the configuration tree.
32
     *
33
     * @return TreeBuilder
34
     */
35 27
    public function getConfigTreeBuilder()
36
    {
37 27
        $treeBuilder = new TreeBuilder();
38 27
        $rootNode = $treeBuilder->root('fos_elastica', 'array');
39
40 27
        $this->addClientsSection($rootNode);
41 27
        $this->addIndexesSection($rootNode);
42
43
        $rootNode
44 27
            ->children()
45 27
                ->scalarNode('default_client')
46 27
                    ->info('Defaults to the first client defined')
47 27
                ->end()
48 27
                ->scalarNode('default_index')
49 27
                    ->info('Defaults to the first index defined')
50 27
                ->end()
51 27
                ->scalarNode('default_manager')->defaultValue('orm')->end()
52 27
                ->arrayNode('serializer')
53 27
                    ->treatNullLike(array())
54 27
                    ->children()
55 27
                        ->scalarNode('callback_class')->defaultValue('FOS\ElasticaBundle\Serializer\Callback')->end()
56 27
                        ->scalarNode('serializer')->defaultValue('serializer')->end()
57 27
                    ->end()
58 27
                ->end()
59 27
            ->end()
60
        ;
61
62 27
        return $treeBuilder;
63
    }
64
65
    /**
66
     * Adds the configuration for the "clients" key.
67
     */
68 27
    private function addClientsSection(ArrayNodeDefinition $rootNode)
69
    {
70
        $rootNode
71 27
            ->fixXmlConfig('client')
72 27
            ->children()
73 27
                ->arrayNode('clients')
74 27
                    ->useAttributeAsKey('id')
75 27
                    ->prototype('array')
76 27
                        ->performNoDeepMerging()
77
                        // BC - Renaming 'servers' node to 'connections'
78 27
                        ->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 27
                        })
86 27
                        ->end()
87
                        // Elastica names its properties with camel case, support both
88 27
                        ->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 27
                        })
96 27
                        ->end()
97
                        // If there is no connections array key defined, assume a single connection.
98 27
                        ->beforeNormalization()
99
                        ->ifTrue(function ($v) { return is_array($v) && !array_key_exists('connections', $v); })
100
                        ->then(function ($v) {
101
                            return array(
102 26
                                'connections' => array($v),
103
                            );
104 27
                        })
105 27
                        ->end()
106 27
                        ->children()
107 27
                            ->arrayNode('connections')
108 27
                                ->requiresAtLeastOneElement()
109 27
                                ->prototype('array')
110 27
                                    ->fixXmlConfig('header')
111 27
                                    ->children()
112 27
                                        ->scalarNode('url')
113 27
                                            ->validate()
114
                                                ->ifTrue(function ($url) { return $url && substr($url, -1) !== '/'; })
115
                                                ->then(function ($url) { return $url.'/'; })
116 27
                                            ->end()
117 27
                                        ->end()
118 27
                                        ->scalarNode('host')->end()
119 27
                                        ->scalarNode('port')->end()
120 27
                                        ->scalarNode('proxy')->end()
121 27
                                        ->scalarNode('aws_access_key_id')->end()
122 27
                                        ->scalarNode('aws_secret_access_key')->end()
123 27
                                        ->scalarNode('aws_region')->end()
124 27
                                        ->scalarNode('aws_session_token')->end()
125 27
                                        ->scalarNode('logger')
126 27
                                            ->defaultValue($this->debug ? 'fos_elastica.logger' : false)
127 27
                                            ->treatNullLike('fos_elastica.logger')
128 27
                                            ->treatTrueLike('fos_elastica.logger')
129 27
                                        ->end()
130 27
                                        ->booleanNode('compression')->defaultValue(false)->end()
131 27
                                        ->arrayNode('headers')
132 27
                                            ->useAttributeAsKey('name')
133 27
                                            ->prototype('scalar')->end()
134 27
                                        ->end()
135 27
                                        ->scalarNode('transport')->end()
136 27
                                        ->scalarNode('timeout')->end()
137 27
                                        ->scalarNode('connectTimeout')->end()
138 27
                                        ->scalarNode('retryOnConflict')
139 27
                                            ->defaultValue(0)
140 27
                                        ->end()
141 27
                                    ->end()
142 27
                                ->end()
143 27
                            ->end()
144 27
                            ->scalarNode('timeout')->end()
145 27
                            ->scalarNode('connectTimeout')->end()
146 27
                            ->scalarNode('headers')->end()
147 27
                            ->scalarNode('connectionStrategy')->defaultValue('Simple')->end()
148 27
                        ->end()
149 27
                    ->end()
150 27
                ->end()
151 27
            ->end()
152
        ;
153 27
    }
154
155
    /**
156
     * Adds the configuration for the "indexes" key.
157
     */
158 27
    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 27
            ->fixXmlConfig('index')
162 27
            ->children()
163 27
                ->arrayNode('indexes')
164 27
                    ->useAttributeAsKey('name')
165 27
                    ->prototype('array')
166 27
                        ->children()
167 27
                            ->scalarNode('index_name')
168 27
                                ->info('Defaults to the name of the index, but can be modified if the index name is different in ElasticSearch')
169 27
                            ->end()
170 27
                            ->booleanNode('use_alias')->defaultValue(false)->end()
171 27
                            ->scalarNode('client')->end()
172 27
                            ->scalarNode('finder')
173 27
                                ->treatNullLike(true)
174 27
                                ->defaultFalse()
175 27
                            ->end()
176 27
                            ->arrayNode('type_prototype')
177 27
                                ->children()
178 27
                                    ->scalarNode('analyzer')->end()
179 27
                                    ->append($this->getPersistenceNode())
180 27
                                    ->append($this->getSerializerNode())
181 27
                                ->end()
182 27
                            ->end()
183 27
                            ->variableNode('settings')->defaultValue(array())->end()
184 27
                        ->end()
185 27
                        ->append($this->getTypesNode())
186 27
                    ->end()
187 27
                ->end()
188 27
            ->end()
189
        ;
190 27
    }
191
192
    /**
193
     * Returns the array node used for "types".
194
     */
195 27
    protected function getTypesNode()
196
    {
197 27
        $builder = new TreeBuilder();
198 27
        $node = $builder->root('types');
199
200
        $node
201 27
            ->useAttributeAsKey('name')
202 27
            ->prototype('array')
203 27
                ->treatNullLike(array())
204 27
                ->beforeNormalization()
205 27
                ->ifNull()
206 27
                ->thenEmptyArray()
207 27
                ->end()
208
                // BC - Renaming 'mappings' node to 'properties'
209 27
                ->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 27
                })
217 27
                ->end()
218
                // BC - Support the old is_indexable_callback property
219 27
                ->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 27
                })
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 27
                })
241 27
                ->end()
242
                // Support multiple dynamic_template formats to match the old bundle style
243
                // and the way ElasticSearch expects them
244 27
                ->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 27
                })
260 27
                ->end()
261 27
                ->children()
262 27
                    ->booleanNode('date_detection')->end()
263 27
                    ->arrayNode('dynamic_date_formats')->prototype('scalar')->end()->end()
264 27
                    ->scalarNode('analyzer')->end()
265 27
                    ->booleanNode('numeric_detection')->end()
266 27
                    ->scalarNode('dynamic')->end()
267 27
                    ->variableNode('indexable_callback')->end()
268 27
                    ->append($this->getPersistenceNode())
269 27
                    ->append($this->getSerializerNode())
270 27
                ->end()
271 27
                ->append($this->getIdNode())
272 27
                ->append($this->getPropertiesNode())
273 27
                ->append($this->getDynamicTemplateNode())
274 27
                ->append($this->getSourceNode())
275 27
                ->append($this->getBoostNode())
276 27
                ->append($this->getRoutingNode())
277 27
                ->append($this->getParentNode())
278 27
                ->append($this->getAllNode())
279 27
                ->append($this->getTimestampNode())
280 27
                ->append($this->getTtlNode())
281 27
            ->end()
282
        ;
283
284 27
        return $node;
285
    }
286
287
    /**
288
     * Returns the array node used for "properties".
289
     */
290 27
    protected function getPropertiesNode()
291
    {
292 27
        $builder = new TreeBuilder();
293 27
        $node = $builder->root('properties');
294
295
        $node
296 27
            ->useAttributeAsKey('name')
297 27
            ->prototype('variable')
298 27
                ->treatNullLike(array());
299
300 27
        return $node;
301
    }
302
303
    /**
304
     * Returns the array node used for "dynamic_templates".
305
     */
306 27
    public function getDynamicTemplateNode()
307
    {
308 27
        $builder = new TreeBuilder();
309 27
        $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 27
            ->prototype('array')
313 27
                ->prototype('array')
314 27
                    ->children()
315 27
                        ->scalarNode('match')->end()
316 27
                        ->scalarNode('unmatch')->end()
317 27
                        ->scalarNode('match_mapping_type')->end()
318 27
                        ->scalarNode('path_match')->end()
319 27
                        ->scalarNode('path_unmatch')->end()
320 27
                        ->scalarNode('match_pattern')->end()
321 27
                        ->arrayNode('mapping')
322 27
                            ->prototype('variable')
323 27
                                ->treatNullLike(array())
324 27
                            ->end()
325 27
                        ->end()
326 27
                    ->end()
327 27
                ->end()
328 27
            ->end()
329
        ;
330
331 27
        return $node;
332
    }
333
334
    /**
335
     * Returns the array node used for "_id".
336
     */
337 27 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 27
        $builder = new TreeBuilder();
340 27
        $node = $builder->root('_id');
341
342
        $node
343 27
            ->children()
344 27
            ->scalarNode('path')->end()
345 27
            ->end()
346
        ;
347
348 27
        return $node;
349
    }
350
351
    /**
352
     * Returns the array node used for "_source".
353
     */
354 27
    protected function getSourceNode()
355
    {
356 27
        $builder = new TreeBuilder();
357 27
        $node = $builder->root('_source');
358
359
        $node
360 27
            ->children()
361 27
                ->arrayNode('excludes')
362 27
                    ->useAttributeAsKey('name')
363 27
                    ->prototype('scalar')->end()
364 27
                ->end()
365 27
                ->arrayNode('includes')
366 27
                    ->useAttributeAsKey('name')
367 27
                    ->prototype('scalar')->end()
368 27
                ->end()
369 27
                ->scalarNode('compress')->end()
370 27
                ->scalarNode('compress_threshold')->end()
371 27
                ->scalarNode('enabled')->defaultTrue()->end()
372 27
            ->end()
373
        ;
374
375 27
        return $node;
376
    }
377
378
    /**
379
     * Returns the array node used for "_boost".
380
     */
381 27
    protected function getBoostNode()
382
    {
383 27
        $builder = new TreeBuilder();
384 27
        $node = $builder->root('_boost');
385
386
        $node
387 27
            ->children()
388 27
                ->scalarNode('name')->end()
389 27
                ->scalarNode('null_value')->end()
390 27
            ->end()
391
        ;
392
393 27
        return $node;
394
    }
395
396
    /**
397
     * Returns the array node used for "_routing".
398
     */
399 27 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 27
        $builder = new TreeBuilder();
402 27
        $node = $builder->root('_routing');
403
404
        $node
405 27
            ->children()
406 27
                ->scalarNode('required')->end()
407 27
                ->scalarNode('path')->end()
408 27
            ->end()
409
        ;
410
411 27
        return $node;
412
    }
413
414
    /**
415
     * Returns the array node used for "_parent".
416
     */
417 27
    protected function getParentNode()
418
    {
419 27
        $builder = new TreeBuilder();
420 27
        $node = $builder->root('_parent');
421
422
        $node
423 27
            ->children()
424 27
                ->scalarNode('type')->end()
425 27
                ->scalarNode('property')->defaultValue(null)->end()
426 27
                ->scalarNode('identifier')->defaultValue('id')->end()
427 27
            ->end()
428
        ;
429
430 27
        return $node;
431
    }
432
433
    /**
434
     * Returns the array node used for "_all".
435
     */
436 27
    protected function getAllNode()
437
    {
438 27
        $builder = new TreeBuilder();
439 27
        $node = $builder->root('_all');
440
441
        $node
442 27
            ->children()
443 27
            ->scalarNode('enabled')->defaultValue(true)->end()
444 27
            ->scalarNode('analyzer')->end()
445 27
            ->end()
446
        ;
447
448 27
        return $node;
449
    }
450
451
    /**
452
     * Returns the array node used for "_timestamp".
453
     */
454 27 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 27
        $builder = new TreeBuilder();
457 27
        $node = $builder->root('_timestamp');
458
459
        $node
460 27
            ->children()
461 27
            ->scalarNode('enabled')->defaultValue(true)->end()
462 27
            ->scalarNode('path')->end()
463 27
            ->scalarNode('format')->end()
464 27
            ->scalarNode('store')->end()
465 27
            ->scalarNode('index')->end()
466 27
            ->end()
467
        ;
468
469 27
        return $node;
470
    }
471
472
    /**
473
     * Returns the array node used for "_ttl".
474
     */
475 27 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 27
        $builder = new TreeBuilder();
478 27
        $node = $builder->root('_ttl');
479
480
        $node
481 27
            ->children()
482 27
            ->scalarNode('enabled')->defaultValue(true)->end()
483 27
            ->scalarNode('default')->end()
484 27
            ->scalarNode('store')->end()
485 27
            ->scalarNode('index')->end()
486 27
            ->end()
487
        ;
488
489 27
        return $node;
490
    }
491
492
    /**
493
     * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition
494
     */
495 27
    protected function getPersistenceNode()
496
    {
497 27
        $builder = new TreeBuilder();
498 27
        $node = $builder->root('persistence');
499
500
        $node
501 27
            ->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 27
                    ->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 27
                    ->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 27
                    ->thenInvalid('Hints are only supported by the "orm" driver')
508 27
            ->end()
509 27
            ->children()
510 27
                ->scalarNode('driver')
511 27
                    ->defaultValue('orm')
512 27
                    ->validate()
513 27
                    ->ifNotInArray($this->supportedDrivers)
514 27
                        ->thenInvalid('The driver %s is not supported. Please choose one of '.json_encode($this->supportedDrivers))
515 27
                    ->end()
516 27
                ->end()
517 27
                ->scalarNode('model')->defaultValue(null)->end()
518 27
                ->scalarNode('repository')->end()
519 27
                ->scalarNode('identifier')->defaultValue('id')->end()
520 27
                ->arrayNode('provider')
521 27
                    ->addDefaultsIfNotSet()
522 27
                    ->children()
523 27
                        ->scalarNode('batch_size')->defaultValue(100)->end()
524 27
                        ->scalarNode('clear_object_manager')->defaultTrue()->end()
525 27
                        ->scalarNode('debug_logging')
526 27
                            ->defaultValue($this->debug)
527 27
                            ->treatNullLike(true)
528 27
                        ->end()
529 27
                        ->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end()
530 27
                        ->scalarNode('service')->end()
531 27
                    ->end()
532 27
                ->end()
533 27
                ->arrayNode('listener')
534 27
                    ->addDefaultsIfNotSet()
535 27
                    ->children()
536 27
                        ->scalarNode('insert')->defaultTrue()->end()
537 27
                        ->scalarNode('update')->defaultTrue()->end()
538 27
                        ->scalarNode('delete')->defaultTrue()->end()
539 27
                        ->scalarNode('flush')->defaultTrue()->end()
540 27
                        ->scalarNode('logger')
541 27
                            ->defaultFalse()
542 27
                            ->treatNullLike('fos_elastica.logger')
543 27
                            ->treatTrueLike('fos_elastica.logger')
544 27
                        ->end()
545 27
                        ->scalarNode('service')->end()
546 27
                    ->end()
547 27
                ->end()
548 27
                ->arrayNode('finder')
549 27
                    ->addDefaultsIfNotSet()
550 27
                    ->children()
551 27
                        ->scalarNode('service')->end()
552 27
                    ->end()
553 27
                ->end()
554 27
                ->arrayNode('elastica_to_model_transformer')
555 27
                    ->addDefaultsIfNotSet()
556 27
                    ->children()
557 27
                        ->arrayNode('hints')
558 27
                            ->prototype('array')
559 27
                                ->children()
560 27
                                    ->scalarNode('name')->end()
561 27
                                    ->scalarNode('value')->end()
562 27
                                ->end()
563 27
                            ->end()
564 27
                        ->end()
565 27
                        ->booleanNode('hydrate')->defaultTrue()->end()
566 27
                        ->booleanNode('ignore_missing')
567 27
                            ->defaultFalse()
568 27
                            ->info('Silently ignore results returned from Elasticsearch without corresponding persistent object.')
569 27
                        ->end()
570 27
                        ->scalarNode('query_builder_method')->defaultValue('createQueryBuilder')->end()
571 27
                        ->scalarNode('service')->end()
572 27
                    ->end()
573 27
                ->end()
574 27
                ->arrayNode('model_to_elastica_transformer')
575 27
                    ->addDefaultsIfNotSet()
576 27
                    ->children()
577 27
                        ->scalarNode('service')->end()
578 27
                    ->end()
579 27
                ->end()
580 27
                ->arrayNode('persister')
581 27
                    ->addDefaultsIfNotSet()
582 27
                    ->children()
583 27
                        ->scalarNode('service')->end()
584 27
                    ->end()
585 27
                ->end()
586 27
            ->end();
587
588 27
        return $node;
589
    }
590
591
    /**
592
     * @return ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition
593
     */
594 27
    protected function getSerializerNode()
595
    {
596 27
        $builder = new TreeBuilder();
597 27
        $node = $builder->root('serializer');
598
599
        $node
600 27
            ->addDefaultsIfNotSet()
601 27
            ->children()
602 27
                ->arrayNode('groups')
603 27
                    ->treatNullLike(array())
604 27
                    ->prototype('scalar')->end()
605 27
                ->end()
606 27
                ->scalarNode('version')->end()
607 27
                ->booleanNode('serialize_null')
608 27
                    ->defaultFalse()
609 27
                ->end()
610 27
            ->end();
611
612 27
        return $node;
613
    }
614
}
615