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:10
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
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 47
        $prototype = $node->useAttributeAsKey('name', false)->prototype('array');
0 ignored issues
show
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

19
        $prototype = $node->useAttributeAsKey('name', false)->/** @scrutinizer ignore-call */ prototype('array');
Loading history...
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

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