Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 59
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 54
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 54
nc 1
nop 0
dl 0
loc 59
ccs 54
cts 54
cp 1
crap 1
rs 9.0036
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace ElevenLabs\ApiServiceBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\ArrayNode;
6
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
10
11
/**
12
 * This class contains the configuration information for the bundle.
13
 *
14
 * This information is solely responsible for how the different configuration
15
 * sections are normalized, and merged.
16
 */
17
class Configuration implements ConfigurationInterface
18
{
19
    /**
20
     * Whether to use the debug mode.
21
     *
22
     * @see https://github.com/doctrine/DoctrineBundle/blob/v1.5.2/DependencyInjection/Configuration.php#L31-L41
23
     *
24
     * @var bool
25
     */
26
    private $debug;
27
28
    /**
29
     * @param bool $debug
30
     */
31 8
    public function __construct($debug)
32
    {
33 8
        $this->debug = (bool) $debug;
34 8
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 8
    public function getConfigTreeBuilder()
40
    {
41 8
        $treeBuilder = new TreeBuilder();
42 8
        $rootNode = $treeBuilder->root('api_service');
43
44
        $rootNode
45 8
            ->children()
46 8
                ->arrayNode('default_services')
47 8
                    ->addDefaultsIfNotSet()
48 8
                    ->info('Configure which services to use when generating API service classes')
49 8
                    ->children()
50 8
                        ->scalarNode('client')->defaultValue('httplug.client')->end()
51 8
                        ->scalarNode('message_factory')->defaultValue('httplug.message_factory')->end()
52 8
                        ->scalarNode('uri_factory')->defaultValue('httplug.uri_factory')->end()
53 8
                    ->end()
54 8
                ->end()
55 8
                ->arrayNode('cache')
56 8
                    ->info('Activate API schemas cache')
57 8
                    ->canBeEnabled()
58 8
                    ->children()
59 8
                        ->scalarNode('service')->info('The service Id that should be used for caching schemas')->isRequired()->end()
60 8
                    ->end()
61 8
                ->end()
62 8
                ->arrayNode('pagination')
63 8
                    ->info('Pagination providers')
64 8
                    ->addDefaultsIfNotSet()
65 8
                    ->children()
66 8
                        ->arrayNode('header')
67 8
                            ->children()
68 8
                                ->scalarNode('page')->defaultValue('X-Page')->end()
69 8
                                ->scalarNode('perPage')->defaultValue('X-Per-Page')->end()
70 8
                                ->scalarNode('totalPages')->defaultValue('X-Total-Pages')->end()
71 8
                                ->scalarNode('totalItems')->defaultValue('X-Total-Items')->end()
72 8
                            ->end()
73 8
                        ->end()
74 8
                    ->end()
75 8
                ->end()
76 8
                ->arrayNode('apis')
77 8
                    ->info('Declare API services')
78 8
                    ->useAttributeAsKey('name')
79 8
                    ->prototype('array')
80 8
                    ->children()
81 8
                        ->scalarNode('schema')->info('Absolute path to the OpenAPI/Swagger2.0 schema')->isRequired()->end()
82 8
                        ->scalarNode('client')->info('Use a specific HTTP client for an API Service')->defaultValue('api_service.client')->end()
83 8
                        ->arrayNode('config')
84 8
                            ->addDefaultsIfNotSet()
85 8
                            ->children()
86 8
                                ->scalarNode('baseUri')->defaultValue(null)->info('The uri of your service (ex: http://domain.tld)')->end()
87 8
                                ->scalarNode('validateRequest')->defaultTrue()->info('Validate the request before sending it')->end()
88 8
                                ->scalarNode('validateResponse')->defaultFalse()->info('Validate the response before sending it')->end()
89 8
                                ->scalarNode('returnResponse')->defaultFalse()->info('Return a Response object instead of a resource')->end()
90 8
                            ->end()
91 8
                        ->end()
92
93 8
                    ->end()
94 8
                ->end()
95 8
            ->end();
96
97 8
        return $treeBuilder;
98
    }
99
}
100