Passed
Push — master ( 57db9a...01c2bb )
by Michael
02:04
created

JsonApiConfiguration::processClients()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

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