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

Completed
Push — master ( 180290...4c80a4 )
by Jérémiah
01:37
created

ObjectTypeDefinition::treatResolveField()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4.0039

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 15
cts 16
cp 0.9375
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 13
nc 1
nop 1
crap 4.0039
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 18
    public function getDefinition()
20
    {
21 18
        $builder = new TreeBuilder();
22 18
        $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 18
            ->children()
26 18
                ->append($this->nameSection())
27 18
                ->append($this->outputFieldsSelection('fields'))
28 18
                ->append($this->descriptionSection())
29 18
                ->arrayNode('interfaces')
30 18
                    ->prototype('scalar')->info('One of internal or custom interface types.')->end()
31 18
                ->end()
32 18
                ->variableNode('isTypeOf')->end()
33 18
                ->variableNode('resolveField')->end()
34 18
                ->variableNode('fieldsDefaultAccess')
35 18
                ->info('Default access control to fields (expression language can be use here)')
36 18
                ->end()
37 18
            ->end();
38
39 18
        $this->treatFieldsDefaultAccess($node);
40 18
        $this->treatResolveField($node);
41
42 18
        return $node;
43
    }
44
45
    /**
46
     * set empty fields.access with fieldsDefaultAccess values if is set?
47
     *
48
     * @param ArrayNodeDefinition $node
49
     */
50 18
    private function treatFieldsDefaultAccess(ArrayNodeDefinition $node)
51
    {
52 18
        $node->validate()
53
            ->ifTrue(function ($v) {
54 12
                return array_key_exists('fieldsDefaultAccess', $v) && null !== $v['fieldsDefaultAccess'];
55 18
            })
56
            ->then(function ($v) {
57 1
                foreach ($v['fields'] as &$field) {
58 1
                    if (array_key_exists('access', $field) && null !== $field['access']) {
59 1
                        continue;
60
                    }
61
62 1
                    $field['access'] = $v['fieldsDefaultAccess'];
63 1
                }
64
65 1
                return $v;
66 18
            })
67 18
        ->end();
68 18
    }
69
70
    /**
71
     * resolveField is set as fields default resolver if not set
72
     * then remove resolveField to keep "access" feature
73
     * TODO(mcg-web) : get a cleaner way to use resolveField combine with "access" feature.
74
     *
75
     * @param ArrayNodeDefinition $node
76
     */
77 18
    private function treatResolveField(ArrayNodeDefinition $node)
78
    {
79 18
        $node->validate()
80
            ->ifTrue(function ($v) {
81 12
                return array_key_exists('resolveField', $v) && null !== $v['resolveField'];
82 18
            })
83 18
            ->then(function ($v) {
84 1
                $resolveField = $v['resolveField'];
85 1
                unset($v['resolveField']);
86 1
                foreach ($v['fields'] as &$field) {
87 1
                    if (!empty($field['resolve'])) {
88
                        continue;
89
                    }
90
91 1
                    $field['resolve'] = $resolveField;
92 1
                }
93
94 1
                return $v;
95 18
            })
96 18
        ->end();
97 18
    }
98
}
99