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
Pull Request — master (#731)
by Vincent
24:54
created

ObjectTypeDefinition::treatFieldsDefaultPublic()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 0
cp 0
rs 9.9666
cc 4
nc 1
nop 1
crap 20
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(fn ($v) => isset($v['fieldsDefaultAccess']))
61
            ->then(function ($v) {
62 1
                foreach ($v['fields'] as &$field) {
63
                    if (array_key_exists('access', $field) && null !== $field['access']) {
64
                        continue;
65 1
                    }
66 47
                    $field['access'] = $v['fieldsDefaultAccess'];
67 47
                }
68 47
69
                return $v;
70
            })
71
        ->end();
72
    }
73 47
74
    /**
75 47
     * set empty fields.accessConfig with fieldsDefaultAccessConfig values if is set?
76 47
     */
77 47
    private function treatFieldsDefaultAccessConfig(ArrayNodeDefinition $node): void
78 1
    {
79 1
        $node->validate()
80 1
            ->ifTrue(fn ($v) => isset($v['fieldsDefaultAccessConfig']))
81
            ->then(function ($v) {
82 1
                foreach ($v['fields'] as &$field) {
83
                    if (isset($field['accessConfig'])) {
84
                        continue;
85 1
                    }
86 47
87 47
                    $field['accessConfig'] = $v['fieldsDefaultAccessConfig'];
88 47
                }
89
90 6
                return $v;
91
            })
92
        ->end();
93
    }
94
95
    /**
96
     * set empty fields.public with fieldsDefaultPublic values if is set?
97
     */
98
    private function treatFieldsDefaultPublic(ArrayNodeDefinition $node): void
99
    {
100
        $node->validate()
101
            ->ifTrue(fn ($v) => isset($v['fieldsDefaultPublic']))
102
            ->then(function ($v) {
103
                foreach ($v['fields'] as &$field) {
104
                    if (array_key_exists('public', $field) && null !== $field['public']) {
105
                        continue;
106
                    }
107
                    $field['public'] = $v['fieldsDefaultPublic'];
108
                }
109
110
                return $v;
111
            })
112
        ->end();
113
    }
114
}
115