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 (#423)
by
unknown
20:29
created

RelayProcessor::processRelayConfigs()   C

Complexity

Conditions 12
Paths 130

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 6.7166
c 0
b 0
f 0
cc 12
nc 130
nop 3
crap 12

How to fix   Complexity   

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
namespace Overblog\GraphQLBundle\Config\Processor;
4
5
use Overblog\GraphQLBundle\Definition\Builder\MappingInterface;
6
use Overblog\GraphQLBundle\Relay\Connection\ConnectionDefinition;
7
use Overblog\GraphQLBundle\Relay\Mutation\InputDefinition;
8
use Overblog\GraphQLBundle\Relay\Mutation\PayloadDefinition;
9
use Overblog\GraphQLBundle\Relay\Node\NodeDefinition;
10
11
final class RelayProcessor implements ProcessorInterface
12
{
13
    const RELAY_DEFINITION_MAPPING = [
14
        'relay-connection' => ConnectionDefinition::class,
15
        'relay-node' => NodeDefinition::class,
16
        'relay-mutation-input' => InputDefinition::class,
17
        'relay-mutation-payload' => PayloadDefinition::class,
18
    ];
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public static function process(array $configs)
24
    {
25 37
        foreach (static::RELAY_DEFINITION_MAPPING as $typeName => $definitionBuilderClass) {
26
            $configs = self::processRelayConfigs($typeName, $definitionBuilderClass, $configs);
27 37
        }
28 37
29
        return $configs;
30
    }
31 37
32
    private static function processRelayConfigs($typeName, $definitionBuilderClass, array $configs)
33
    {
34 37
        foreach ($configs as $name => $config) {
35
            if (isset($config['type']) && \is_string($config['type']) && $typeName === $config['type']) {
36 37
                
37 37
                $configInherits = isset($config['inherits']) && \is_array($config['inherits']) ? $config['inherits'] : [];
38 18
                                
39
                $config = isset($config['config']) && \is_array($config['config']) ? $config['config'] : [];
40 18
41 18
                if (empty($config['class_name'])) {
42
                    $config['class_name'] = \sprintf('%sType', $name);
43 18
                }
44 17
                if (empty($config['name'])) {
45
                    $config['name'] = $name;
46
                }
47
48 18
                /** @var MappingInterface $builder */
49
                $builder = new $definitionBuilderClass();
50 18
51
                $connectionDefinition = $builder->toMappingDefinition($config);
52 37
53
                if (!empty($configInherits)) {
54
                    $connectionDefinition[$name]['inherits'] = $configInherits;
55
                }
56 37
                
57
                $configs = \array_replace($configs, $connectionDefinition);
58
            }
59
        }
60
61
        return $configs;
62
    }
63
}
64