Test Failed
Push — master ( b71f19...57db9a )
by Michael
02:20
created

JsonApiConfiguration::processEndpoints()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 1
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Bundle\JsonApiBundle\DependencyInjection;
5
6
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
10
/**
11
 * Class JsonApiConfiguration
12
 *
13
 * @package Mikemirten\Bundle\JsonApiBundle\DependencyInjection
14 2
 */
15
class JsonApiConfiguration implements ConfigurationInterface
16 2
{
17 2
    /**
18
     * {@inheritdoc}
19 2
     */
20 2
    public function getConfigTreeBuilder()
21
    {
22
        $builder  = new TreeBuilder();
23
        $children = $builder->root(JsonApiExtension::ALIAS)->children();
24
25
        $this->processMappers($children);
26
        $this->processClients($children);
27 2
28 2
        return $builder;
29 2
    }
30 2
31
    /**
32 2
     * Process mappers
33
     *
34
     * @param NodeBuilder $builder
35
     */
36
    protected function processMappers(NodeBuilder $builder): void
37
    {
38
        $builder->arrayNode('mappers')
39
            ->defaultValue(['default' => [
40
                'handlers' => [
41
                    'attribute',
42
                    'relationship',
43
                    'link'
44
                ]
45
            ]])
46
            ->prototype('array')
47
                ->children()
48
                    ->arrayNode('handlers')
49
                        ->prototype('scalar');
50
    }
51
52
    /**
53
     * Process http-clients
54
     *
55
     * @param NodeBuilder $builder
56
     */
57
    protected function processClients(NodeBuilder $builder): void
58
    {
59
        $children = $builder->arrayNode('http_clients')
60
            ->prototype('array')
61
                ->children()
62
                    ->scalarNode('base_url')
63
                        ->isRequired()
64
                        ->cannotBeEmpty()
65
                    ->end()
66
67
                    ->arrayNode('decorators')
68
                        ->prototype('scalar')
69
                        ->end()
70
                    ->end();
71
72
        $this->processEndpoints($children);
73
    }
74
75
    /**
76
     * Process endpoints of client
77
     *
78
     * @param NodeBuilder $builder
79
     */
80
    protected function processEndpoints(NodeBuilder $builder): void
81
    {
82
        $builder->arrayNode('resources')
83
            ->prototype('array')
84
                ->children()
85
                    ->scalarNode('path')
86
                        ->isRequired()
87
                        ->cannotBeEmpty()
88
                    ->end()
89
90
                    ->arrayNode('methods')
91
                        ->prototype('array')
92
                            ->children();
93
    }
94
}