Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — master ( 452341...d2fd23 )
by Jérémiah
06:57
created

ObjectTypeDefinition::getDefinition()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 23
cts 23
cp 1
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 24
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLBundle package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Overblog\GraphQLBundle\Config;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
17
class ObjectTypeDefinition extends TypeWithOutputFieldsDefinition
18
{
19 20
    public function getDefinition()
20
    {
21 20
        $builder = new TreeBuilder();
22 20
        $node = $builder->root('_object_config');
23
24
        $node
0 ignored issues
show
Bug introduced by
The method variableNode() does not seem to exist on object<Symfony\Component...odeDefinitionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25 20
            ->children()
26 20
                ->append($this->nameSection())
27 20
                ->append($this->outputFieldsSelection('fields'))
28 20
                ->append($this->descriptionSection())
29 20
                ->arrayNode('interfaces')
30 20
                    ->prototype('scalar')->info('One of internal or custom interface types.')->end()
31 20
                ->end()
32 20
                ->variableNode('isTypeOf')->end()
33 20
                ->variableNode('resolveField')->end()
34 20
                ->variableNode('fieldsDefaultAccess')
35 20
                    ->info('Default access control to fields (expression language can be use here)')
36 20
                ->end()
37 20
                ->variableNode('fieldsDefaultPublic')
38 20
                    ->info('Default public control to fields (expression language can be use here)')
39 20
                ->end()
40 20
            ->end();
41
42 20
        $this->treatFieldsDefaultAccess($node);
43 20
        $this->treatFieldsDefaultPublic($node);
44 20
        $this->treatResolveField($node);
45
46 20
        return $node;
47
    }
48
49
    /**
50
     * set empty fields.access with fieldsDefaultAccess values if is set?
51
     *
52
     * @param ArrayNodeDefinition $node
53
     */
54 20 View Code Duplication
    private function treatFieldsDefaultAccess(ArrayNodeDefinition $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56 20
        $node->validate()
57
            ->ifTrue(function ($v) {
58 14
                return array_key_exists('fieldsDefaultAccess', $v) && null !== $v['fieldsDefaultAccess'];
59 20
            })
60
            ->then(function ($v) {
61 1
                foreach ($v['fields'] as &$field) {
62 1
                    if (array_key_exists('access', $field) && null !== $field['access']) {
63 1
                        continue;
64
                    }
65
66 1
                    $field['access'] = $v['fieldsDefaultAccess'];
67 1
                }
68
69 1
                return $v;
70 20
            })
71 20
        ->end();
72 20
    }
73
74
    /**
75
     * set empty fields.public with fieldsDefaultPublic values if is set?
76
     *
77
     * @param ArrayNodeDefinition $node
78
     */
79 20 View Code Duplication
    private function treatFieldsDefaultPublic(ArrayNodeDefinition $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81 20
        $node->validate()
82
            ->ifTrue(function ($v) {
83 14
                return array_key_exists('fieldsDefaultPublic', $v) && null !== $v['fieldsDefaultPublic'];
84 20
            })
85
            ->then(function ($v) {
86
                foreach ($v['fields'] as &$field) {
87
                    if (array_key_exists('public', $field) && null !== $field['public']) {
88
                        continue;
89
                    }
90
91
                    $field['public'] = $v['fieldsDefaultPublic'];
92
                }
93
94
                return $v;
95 20
            })
96 20
        ->end();
97 20
    }
98
99
    /**
100
     * resolveField is set as fields default resolver if not set
101
     * then remove resolveField to keep "access" feature
102
     * TODO(mcg-web) : get a cleaner way to use resolveField combine with "access" feature.
103
     *
104
     * @param ArrayNodeDefinition $node
105
     */
106 20
    private function treatResolveField(ArrayNodeDefinition $node)
107
    {
108 20
        $node->validate()
109
            ->ifTrue(function ($v) {
110 14
                return array_key_exists('resolveField', $v) && null !== $v['resolveField'];
111 20
            })
112 20
            ->then(function ($v) {
113 1
                $resolveField = $v['resolveField'];
114 1
                unset($v['resolveField']);
115 1
                foreach ($v['fields'] as &$field) {
116 1
                    if (!empty($field['resolve'])) {
117
                        continue;
118
                    }
119
120 1
                    $field['resolve'] = $resolveField;
121 1
                }
122
123 1
                return $v;
124 20
            })
125 20
        ->end();
126 20
    }
127
}
128