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
Pull Request — master (#731)
by Vincent
25:13 queued 10s
created

treatFieldsDefaultAccessConfig()   A

Complexity

Conditions 5
Paths 1

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 9.6111
c 0
b 0
f 0
cc 5
nc 1
nop 1
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Config;
6
7
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
use function array_key_exists;
10
11
class ObjectTypeDefinition extends TypeWithOutputFieldsDefinition
12
{
13 47
    public function getDefinition(): ArrayNodeDefinition
14
    {
15 47
        $builder = new TreeBuilder('_object_config', 'array');
16
17
        /** @var ArrayNodeDefinition $node */
18 47
        $node = $builder->getRootNode();
19
20
        /** @phpstan-ignore-next-line */
21
        $node
22 47
            ->children()
23 47
                ->append($this->validationSection(self::VALIDATION_LEVEL_CLASS))
24 47
                ->append($this->nameSection())
25 47
                ->append($this->outputFieldsSection())
26 47
                ->append($this->fieldsBuilderSection())
27 47
                ->append($this->descriptionSection())
28 47
                ->arrayNode('interfaces')
29 47
                    ->prototype('scalar')->info('One of internal or custom interface types.')->end()
30 47
                ->end()
0 ignored issues
show
Bug introduced by
The method end() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Symfony\Component\Config...ion\Builder\TreeBuilder. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
                ->/** @scrutinizer ignore-call */ end()
Loading history...
31 47
                ->variableNode('isTypeOf')->end()
32 47
                ->variableNode('resolveField')->end()
33 47
                ->variableNode('fieldsDefaultAccess')
34 47
                    ->info('Default access control to fields (expression language can be use here)')
35 47
                ->end()
36 47
                ->arrayNode('fieldsDefaultAccessConfig')
37 47
                    ->addDefaultsIfNotSet()
38 47
                    ->children()
39 47
                        ->booleanNode('nullOnDenied')->defaultFalse()->end()
40
                    ->end()
41 47
                ->end()
42 47
                ->variableNode('fieldsDefaultPublic')
43
                    ->info('Default public control to fields (expression language can be use here)')
44 47
                ->end()
45
            ->end();
46
47
        $this->treatFieldsDefaultAccess($node);
48
        $this->treatFieldsDefaultAccessConfig($node);
49
        $this->treatFieldsDefaultPublic($node);
50 47
51
        return $node;
52 47
    }
53 47
54 37
    /**
55 47
     * set empty fields.access with fieldsDefaultAccess values if is set?
56 47
     */
57 1
    private function treatFieldsDefaultAccess(ArrayNodeDefinition $node): void
58 1
    {
59 1
        $node->validate()
60
            ->ifTrue(function ($v) {
61
                return array_key_exists('fieldsDefaultAccess', $v) && null !== $v['fieldsDefaultAccess'];
62 1
            })
63
            ->then(function ($v) {
64
                foreach ($v['fields'] as &$field) {
65 1
                    if (array_key_exists('access', $field) && null !== $field['access']) {
66 47
                        continue;
67 47
                    }
68 47
                    $field['access'] = $v['fieldsDefaultAccess'];
69
                }
70
71
                return $v;
72
            })
73 47
        ->end();
74
    }
75 47
76 47
    /**
77 47
     * set empty fields.accessConfig with fieldsDefaultAccessConfig values if is set?
78 1
     */
79 1
    private function treatFieldsDefaultAccessConfig(ArrayNodeDefinition $node): void
80 1
    {
81
        $node->validate()
82 1
            ->ifTrue(function ($v) {
83
                return array_key_exists('fieldsDefaultAccessConfig', $v) && null !== $v['fieldsDefaultAccessConfig'];
84
            })
85 1
            ->then(function ($v) {
86 47
                foreach ($v['fields'] as &$field) {
87 47
                    if (array_key_exists('accessConfig', $field) && null !== $field['accessConfig']) {
88 47
                        continue;
89
                    }
90 6
91
                    $field['accessConfig'] = $v['fieldsDefaultAccessConfig'];
92
                }
93
94
                return $v;
95
            })
96
        ->end();
97
    }
98
99
    /**
100
     * set empty fields.public with fieldsDefaultPublic values if is set?
101
     */
102
    private function treatFieldsDefaultPublic(ArrayNodeDefinition $node): void
103
    {
104
        $node->validate()
105
            ->ifTrue(fn ($v) => array_key_exists('fieldsDefaultPublic', $v) && null !== $v['fieldsDefaultPublic'])
106
            ->then(function ($v) {
107
                foreach ($v['fields'] as &$field) {
108
                    if (array_key_exists('public', $field) && null !== $field['public']) {
109
                        continue;
110
                    }
111
                    $field['public'] = $v['fieldsDefaultPublic'];
112
                }
113
114
                return $v;
115
            })
116
        ->end();
117
    }
118
}
119