Configuration   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 73
ccs 55
cts 55
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 11 1
A createExceptionsNode() 0 51 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Faecie\Bundle\JsonApiErrorResponseBundle\DependencyInjection;
6
7
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
8
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
9
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
10
use Symfony\Component\Config\Definition\ConfigurationInterface;
11
12
class Configuration implements ConfigurationInterface
13
{
14
    public const EXCEPTION_ATTRIBUTE_ID = 'id';
15
    public const EXCEPTION_ATTRIBUTE_ABOUT = 'about_link';
16
    public const EXCEPTION_ATTRIBUTE_STATUS = 'status';
17
    public const EXCEPTION_ATTRIBUTE_CODE = 'code';
18
    public const EXCEPTION_ATTRIBUTE_TITLE = 'title';
19
    public const EXCEPTION_ATTRIBUTE_DETAIL = 'detail';
20
21 3
    public function getConfigTreeBuilder()
22
    {
23 3
        $tree = new TreeBuilder();
24 3
        $root = $tree->root('json_api_error_response');
25
        $root
26 3
            ->children()
27 3
            ->append($this->createExceptionsNode())
28 3
            ->end();
29
30 3
        return $tree;
31
    }
32
33 3
    private function createExceptionsNode(): NodeDefinition
34
    {
35 3
        $tree = new TreeBuilder();
36 3
        $node = $tree->root('exceptions');
37 3
        $node->treatNullLike([])
38 3
            ->addDefaultsIfNotSet()
39 3
                ->children()
40 3
                    ->arrayNode('response')
41 3
                    ->defaultValue([])
42 3
                    ->treatNullLike([])
43 3
                    ->useAttributeAsKey('class')
44 3
                    ->info('Exceptions characteristics being exposed as json in response to failed request')
45 3
                    ->prototype('array')
46 3
                    ->addDefaultsIfNotSet()
47 3
                    ->children()
48 3
                        ->scalarNode('class')
49 3
                        ->defaultNull()
50 3
                        ->info('FQCN of Exception class')
51 3
                    ->end()
52 3
                    ->scalarNode(self::EXCEPTION_ATTRIBUTE_ID)
53 3
                        ->defaultNull()
54 3
                        ->info('A unique identifier for this particular occurrence of the problem')
55 3
                    ->end()
56 3
                    ->scalarNode(self::EXCEPTION_ATTRIBUTE_ABOUT)
57 3
                        ->defaultNull()
58 3
                        ->info('A link that leads to further details' .
59 3
                            ' about this particular occurrence of the problem.')
60 3
                    ->end()
61 3
                    ->integerNode(self::EXCEPTION_ATTRIBUTE_STATUS)
62 3
                        ->defaultNull()
63 3
                        ->info('The HTTP status code applicable to this problem')
64 3
                    ->end()
65 3
                    ->scalarNode(self::EXCEPTION_ATTRIBUTE_CODE)
66 3
                        ->isRequired()
67 3
                        ->info('An application-specific error code, expressed as a string value')
68 3
                    ->end()
69 3
                    ->scalarNode(self::EXCEPTION_ATTRIBUTE_TITLE)
70 3
                        ->defaultNull()
71 3
                        ->info('A short, human-readable summary of the problem that SHOULD NOT change ' .
72 3
                            'from occurrence to occurrence of the problem, except for purposes of localization.')
73 3
                    ->end()
74 3
                    ->scalarNode(self::EXCEPTION_ATTRIBUTE_DETAIL)
75 3
                        ->defaultNull()
76 3
                        ->info('A human-readable explanation specific to this occurrence of the problem. ' .
77 3
                            'Like title, this field’s value can be localized.')
78 3
                    ->end()
79 3
                ->end()
80 3
            ->end();
81
82 3
        return $node;
83
    }
84
}
85