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 (#438)
by Vincent
15:04
created

ObjectTypeDefinition   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
eloc 49
dl 0
loc 93
ccs 53
cts 53
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A treatFieldsDefaultPublic() 0 8 2
A getDefinition() 0 28 1
A treatFieldsDefaultAccess() 0 18 5
A treatFieldsRequired() 0 18 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
9
class ObjectTypeDefinition extends TypeWithOutputFieldsDefinition
10
{
11 38
    public function getDefinition()
12
    {
13 38
        $node = self::createNode('_object_config');
14
15
        $node
16 38
            ->children()
17 38
                ->append($this->nameSection())
18 38
                ->append($this->outputFieldsSelection())
19 38
                ->append($this->fieldsBuilderSection())
20 38
                ->append($this->descriptionSection())
21 38
                ->arrayNode('interfaces')
22 38
                    ->prototype('scalar')->info('One of internal or custom interface types.')->end()
23 38
                ->end()
24 38
                ->variableNode('isTypeOf')->end()
25 38
                ->variableNode('resolveField')->end()
26 38
                ->variableNode('fieldsDefaultAccess')
27 38
                    ->info('Default access control to fields (expression language can be use here)')
28 38
                ->end()
29 38
                ->variableNode('fieldsDefaultPublic')
30 38
                    ->info('Default public control to fields (expression language can be use here)')
31 38
                ->end()
32 38
            ->end();
33
34 38
        $this->treatFieldsRequired($node);
35 38
        $this->treatFieldsDefaultAccess($node);
36 38
        $this->treatFieldsDefaultPublic($node);
37
38 38
        return $node;
39
    }
40
41
    /**
42
     * set empty fields.access with fieldsDefaultAccess values if is set?
43
     *
44
     * @param ArrayNodeDefinition $node
45
     */
46 38
    private function treatFieldsDefaultAccess(ArrayNodeDefinition $node): void
47
    {
48 38
        $node->validate()
49
            ->ifTrue(function ($v) {
50 33
                return \array_key_exists('fieldsDefaultAccess', $v) && null !== $v['fieldsDefaultAccess'];
51 38
            })
52
            ->then(function ($v) {
53 1
                foreach ($v['fields'] as &$field) {
54 1
                    if (\array_key_exists('access', $field) && null !== $field['access']) {
55 1
                        continue;
56
                    }
57
58 1
                    $field['access'] = $v['fieldsDefaultAccess'];
59
                }
60
61 1
                return $v;
62 38
            })
63 38
        ->end();
64 38
    }
65
66
    /**
67
     * set empty fields.public with fieldsDefaultPublic values if is set?
68
     *
69
     * @param ArrayNodeDefinition $node
70
     */
71 38
    private function treatFieldsDefaultPublic(ArrayNodeDefinition $node): void
72
    {
73 38
        $node->validate()
74
            ->ifTrue(function ($v) {
75 33
                return empty($v['builders']) && empty($v['fields']);
76 38
            })
77 38
            ->thenInvalid('Unless fields builders are defined, you must define at least one field')
78 38
        ->end();
79 38
    }
80
81
    /**
82
     * if no fields builder is set, ensure we have at least one field definition.
83
     */
84 38
    private function treatFieldsRequired(ArrayNodeDefinition $node): void
85
    {
86 38
        $node->validate()
87
            ->ifTrue(function ($v) {
88 33
                return \array_key_exists('fieldsDefaultPublic', $v) && null !== $v['fieldsDefaultPublic'];
89 38
            })
90
            ->then(function ($v) {
91 1
                foreach ($v['fields'] as &$field) {
92 1
                    if (\array_key_exists('public', $field) && null !== $field['public']) {
93 1
                        continue;
94
                    }
95
96 1
                    $field['public'] = $v['fieldsDefaultPublic'];
97
                }
98
99 1
                return $v;
100 38
            })
101 38
        ->end();
102 38
    }
103
}
104