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 (#682)
by
unknown
06:23
created

outputFieldsSection()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 75
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 60
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 61
c 0
b 0
f 0
dl 0
loc 75
ccs 60
cts 60
cp 1
rs 8.8509
cc 3
nc 1
nop 0
crap 3

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\NodeDefinition;
9
10
abstract class TypeWithOutputFieldsDefinition extends TypeDefinition
11
{
12 47
    protected function outputFieldsSection(): NodeDefinition
13
    {
14 47
        $node = self::createNode('fields');
15
        $node
16 47
            ->isRequired()
17 47
            ->requiresAtLeastOneElement();
0 ignored issues
show
Bug introduced by
The method requiresAtLeastOneElement() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

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

17
            ->/** @scrutinizer ignore-call */ requiresAtLeastOneElement();
Loading history...
18
19
        /* @var ArrayNodeDefinition $prototype */
20 47
        $prototype = $node->useAttributeAsKey('name', false)->prototype('array');
0 ignored issues
show
Bug introduced by
The method useAttributeAsKey() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

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

20
        $prototype = $node->/** @scrutinizer ignore-call */ useAttributeAsKey('name', false)->prototype('array');
Loading history...
Bug introduced by
The method prototype() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

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

20
        $prototype = $node->useAttributeAsKey('name', false)->/** @scrutinizer ignore-call */ prototype('array');
Loading history...
21
22
        $prototype
23 47
            ->beforeNormalization()
24
                // Allow field type short syntax (Field: Type => Field: {type: Type})
25 47
                ->ifTrue(fn ($options) => \is_string($options))
26 47
                ->then(fn ($options) => ['type' => $options])
27 47
            ->end()
28 47
            ->validate()
29
                // Remove empty entries
30
                ->always(function ($value) {
31 37
                    if (empty($value['validationGroups'])) {
32 37
                        unset($value['validationGroups']);
33
                    }
34
35 37
                    if (empty($value['args'])) {
36 37
                        unset($value['args']);
37
                    }
38
39 37
                    return $value;
40 47
                })
41 47
            ->end()
42 47
            ->children()
43 47
                ->append($this->typeSection())
44 47
                ->append($this->validationSection(self::VALIDATION_LEVEL_CLASS))
45 47
                ->arrayNode('validationGroups')
46 47
                    ->beforeNormalization()
47 47
                        ->castToArray()
48 47
                    ->end()
49 47
                    ->prototype('scalar')
50 47
                        ->info('List of validation groups')
51 47
                    ->end()
52 47
                ->end()
53 47
                ->arrayNode('args')
54 47
                    ->info('Array of possible type arguments. Each entry is expected to be an array with following keys: name (string), type')
55 47
                    ->useAttributeAsKey('name', false)
56 47
                    ->prototype('array')
57
                        // Allow arg type short syntax (Arg: Type => Arg: {type: Type})
58 47
                        ->beforeNormalization()
59 47
                            ->ifTrue(fn ($options) => \is_string($options))
60 47
                            ->then(fn ($options) => ['type' => $options])
61 47
                        ->end()
62 47
                        ->children()
63 47
                            ->append($this->typeSection(true))
64 47
                            ->append($this->descriptionSection())
65 47
                            ->append($this->defaultValueSection())
66 47
                            ->append($this->validationSection(self::VALIDATION_LEVEL_PROPERTY))
67 47
                        ->end()
68 47
                    ->end()
69 47
                ->end()
70 47
                ->variableNode('resolve')
71 47
                    ->info('Value resolver (expression language can be used here)')
72 47
                ->end()
73 47
                ->append($this->descriptionSection())
74 47
                ->append($this->deprecationReasonSection())
75 47
                ->variableNode('access')
76 47
                    ->info('Access control to field (expression language can be used here)')
77 47
                ->end()
78 47
                ->variableNode('public')
79 47
                    ->info('Visibility control to field (expression language can be used here)')
80 47
                ->end()
81 47
                ->variableNode('complexity')
82 47
                    ->info('Custom complexity calculator.')
83 47
                ->end()
84 47
            ->end();
85
86 47
        return $node;
87
    }
88
89 47
    protected function fieldsBuilderSection()
90
    {
91 47
        $node = self::createNode('builders');
92
93 47
        $prototype = $node->prototype('array');
94
95
        $prototype
96 47
            ->children()
97 47
                ->variableNode('builder')->isRequired()->end()
98 47
                ->variableNode('builderConfig')->end()
99 47
            ->end();
100
101 47
        return $node;
102
    }
103
}
104