JsonApiConfiguration::processResourceClients()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 15
cts 15
cp 1
rs 9.584
c 0
b 0
f 0
cc 1
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
41
            /* @see https://github.com/symfony/symfony/issues/12304 */
42 7
            ->useAttributeAsKey(true)
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
44 7
            ->defaultValue(['default' => [
45
                'handlers' => [
46
                    'attribute',
47
                    'relationship',
48
                    'link'
49
                ]
50
            ]])
51 7
            ->prototype('array')
52 7
                ->children()
53 7
                    ->arrayNode('handlers')
54 7
                        ->prototype('scalar');
55 7
    }
56
57
    /**
58
     * Process http-client
59
     *
60
     * @param NodeBuilder $builder
61
     */
62 7
    protected function processHttpClient(NodeBuilder $builder)
63
    {
64 7
        $builder->arrayNode('http_client')
65 7
            ->children()
66 7
                ->scalarNode('guzzle_service')
67 7
                ->cannotBeEmpty();
68 7
    }
69
70
    /**
71
     * Process resource-based clients
72
     *
73
     * @param NodeBuilder $builder
74
     */
75 7
    protected function processResourceClients(NodeBuilder $builder)
76
    {
77 7
        $children = $builder->arrayNode('resource_clients')
78
79
            /* @see https://github.com/symfony/symfony/issues/12304 */
80 7
            ->useAttributeAsKey(true)
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
81
82 7
            ->prototype('array')
83 7
                ->children()
84 7
                    ->scalarNode('base_url')
85 7
                        ->isRequired()
86 7
                        ->cannotBeEmpty()
87 7
                    ->end()
88
89 7
                    ->arrayNode('decorators')
90 7
                        ->prototype('scalar')
91 7
                        ->end()
92 7
                    ->end();
93
94 7
        $this->processEndpoints($children);
95 7
    }
96
97
    /**
98
     * Process endpoints of client
99
     *
100
     * @param NodeBuilder $builder
101
     */
102 7
    protected function processEndpoints(NodeBuilder $builder)
103
    {
104 7
        $builder->arrayNode('resources')
105
106
            /* @see https://github.com/symfony/symfony/issues/12304 */
107 7
            ->useAttributeAsKey(true)
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
108
109 7
            ->prototype('array')
110 7
                ->children()
111 7
                    ->scalarNode('path')
112 7
                        ->isRequired()
113 7
                        ->cannotBeEmpty()
114 7
                    ->end()
115
116 7
                    ->arrayNode('methods')
117 7
                        ->prototype('array')
118 7
                            ->children();
119
    }
120
}