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 Timur
06:41
created

outputFieldsSection()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 74
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 60
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 61
dl 0
loc 74
ccs 60
cts 60
cp 1
rs 8.8509
c 0
b 0
f 0
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\NodeDefinition;
8
9
abstract class TypeWithOutputFieldsDefinition extends TypeDefinition
10
{
11 47
    protected function outputFieldsSection(): NodeDefinition
12
    {
13 47
        $node = self::createNode('fields');
14
        $node
15 47
            ->isRequired()
16 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

16
            ->/** @scrutinizer ignore-call */ requiresAtLeastOneElement();
Loading history...
17
18 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

18
        $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

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