Configuration::addDebugNode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace MediaMonks\RestApiBundle\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
final class Configuration implements ConfigurationInterface
10
{
11
    /**
12
     * Generates the configuration tree.
13
     *
14
     * @return TreeBuilder
15
     */
16 5
    public function getConfigTreeBuilder()
17
    {
18 5
        $treeBuilder = new TreeBuilder('mediamonks_rest_api');
19 5
        $rootNode = $treeBuilder->getRootNode();
20
21 5
        $this->addDebugNode($rootNode);
0 ignored issues
show
Compatibility introduced by
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition>. It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
22 5
        $this->addRequestMatcherNode($rootNode);
0 ignored issues
show
Compatibility introduced by
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition>. It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
23 5
        $this->addSerializer($rootNode);
0 ignored issues
show
Compatibility introduced by
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition>. It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
24 5
        $this->addPostMessageOriginNode($rootNode);
0 ignored issues
show
Compatibility introduced by
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition>. It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
25 5
        $this->addResponseModel($rootNode);
0 ignored issues
show
Compatibility introduced by
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition>. It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
26
27 5
        return $treeBuilder;
28
    }
29
30
    /**
31
     * @param ArrayNodeDefinition $node
32
     */
33 5
    private function addDebugNode(ArrayNodeDefinition $node)
34
    {
35 5
        $node->children()
36 5
            ->scalarNode('debug')
37 5
            ->defaultNull()
38 5
            ->end();
39 5
    }
40
41
    /**
42
     * @param ArrayNodeDefinition $node
43
     */
44 5
    private function addRequestMatcherNode(ArrayNodeDefinition $node)
45
    {
46 5
        $node->children()
47 5
            ->arrayNode('request_matcher')
48 5
                ->addDefaultsIfNotSet()
49 5
                    ->children()
50 5
                        ->scalarNode('path')
51 5
                        ->end()
52 5
                        ->arrayNode('whitelist')
53 5
                            ->defaultValue(['~^/api$~', '~^/api/~'])
54 5
                            ->prototype('scalar')
55 5
                            ->end()
56 5
                        ->end()
57 5
                        ->arrayNode('blacklist')
58 5
                            ->defaultValue(['~^/api/doc~'])
59 5
                            ->prototype('scalar')
60 5
                        ->end()
61 5
                    ->end()
62 5
                ->end()
63 5
            ->end();
64 5
    }
65
66
    /**
67
     * @param ArrayNodeDefinition $node
68
     */
69 5
    private function addSerializer(ArrayNodeDefinition $node)
70
    {
71 5
        $node->children()
72 5
            ->scalarNode('serializer')
73 5
            ->defaultValue('json')
74 5
            ->end();
75 5
    }
76
77
    /**
78
     * @param ArrayNodeDefinition $node
79
     */
80 5
    private function addPostMessageOriginNode(ArrayNodeDefinition $node)
81
    {
82 5
        $node->children()
83 5
            ->scalarNode('post_message_origin')
84 5
            ->defaultNull()
85 5
            ->end();
86 5
    }
87
88
    /**
89
     * @param ArrayNodeDefinition $node
90
     */
91 5
    private function addResponseModel(ArrayNodeDefinition $node)
92
    {
93 5
        $node->children()
94 5
            ->scalarNode('response_model')
95 5
            ->defaultNull()
96 5
            ->end();
97 5
    }
98
}
99