Passed
Push — master ( 2006ec...f7310b )
by Michael
03:34
created

JsonApiConfiguration::processResourceClients()   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 7
    public function getConfigTreeBuilder()
21
    {
22 7
        $builder  = new TreeBuilder();
23 7
        $children = $builder->root(JsonApiExtension::ALIAS)->children();
24
25 7
        $this->processMappers($children);
26 7
        $this->processHttpClient($children);
27 7
        $this->processResourceClients($children);
28
29 7
        return $builder;
30
    }
31
32
    /**
33
     * Process mappers
34
     *
35
     * @param NodeBuilder $builder
36
     */
37 7
    protected function processMappers(NodeBuilder $builder)
38
    {
39 7
        $builder->arrayNode('mappers')
40 7
            ->defaultValue(['default' => [
41
                'handlers' => [
42
                    'attribute',
43
                    'relationship',
44
                    'link'
45
                ]
46
            ]])
47 7
            ->prototype('array')
48 7
                ->children()
49 7
                    ->arrayNode('handlers')
50 7
                        ->prototype('scalar');
51 7
    }
52
53
    /**
54
     * Process http-client
55
     *
56
     * @param NodeBuilder $builder
57
     */
58 7
    protected function processHttpClient(NodeBuilder $builder)
59
    {
60 7
        $builder->arrayNode('http_client')
61 7
            ->children()
62 7
                ->scalarNode('guzzle_service')
63 7
                ->cannotBeEmpty();
64 7
    }
65
66
    /**
67
     * Process resource-based clients
68
     *
69
     * @param NodeBuilder $builder
70
     */
71 7
    protected function processResourceClients(NodeBuilder $builder)
72
    {
73 7
        $children = $builder->arrayNode('resource_clients')
74 7
            ->prototype('array')
75 7
                ->children()
76 7
                    ->scalarNode('base_url')
77 7
                        ->isRequired()
78 7
                        ->cannotBeEmpty()
79 7
                    ->end()
80
81 7
                    ->arrayNode('decorators')
82 7
                        ->prototype('scalar')
83 7
                        ->end()
84 7
                    ->end();
85
86 7
        $this->processEndpoints($children);
87 7
    }
88
89
    /**
90
     * Process endpoints of client
91
     *
92
     * @param NodeBuilder $builder
93
     */
94 7
    protected function processEndpoints(NodeBuilder $builder)
95
    {
96 7
        $builder->arrayNode('resources')
97 7
            ->prototype('array')
98 7
                ->children()
99 7
                    ->scalarNode('path')
100 7
                        ->isRequired()
101 7
                        ->cannotBeEmpty()
102 7
                    ->end()
103
104 7
                    ->arrayNode('methods')
105 7
                        ->prototype('array')
106 7
                            ->children();
107
    }
108
}