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 (#277)
by Jérémiah
22:38 queued 19:05
created

SchemaLanguageQueryResolverMap::map()   B

Complexity

Conditions 7
Paths 1

Size

Total Lines 67
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 7.0237
c 0
b 0
f 0
cc 7
eloc 40
nc 1
nop 0

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
namespace Overblog\GraphQLBundle\Tests\Functional\App\Resolver;
4
5
use GraphQL\Error\Error;
6
use GraphQL\Language\AST\StringValueNode;
7
use GraphQL\Type\Definition\ResolveInfo;
8
use GraphQL\Utils;
9
use Overblog\GraphQLBundle\Definition\Argument;
10
use Overblog\GraphQLBundle\Resolver\ResolverMap;
11
12
class SchemaLanguageQueryResolverMap extends ResolverMap
13
{
14
    protected function map()
15
    {
16
        return [
17
            'Query' => [
18
                self::RESOLVE_FIELD => function ($value, Argument $args, \ArrayObject $context, ResolveInfo $info) {
19
                    if ('character' === $info->fieldName) {
20
                        $characters = Characters::getCharacters();
21
                        $id = (int) $args['id'];
22
                        if (isset($characters[$id])) {
23
                            return $characters[$id];
24
                        }
25
                    }
26
27
                    return null;
28
                },
29
                'findHumansByDateOfBirth' => function ($value, Argument $args) {
30
                    $years = $args['years'];
31
32
                    return array_filter(Characters::getHumans(), function ($human) use ($years) {
33
                        return in_array($human['dateOfBirth'], $years);
34
                    });
35
                },
36
                'humans' => [Characters::class, 'getHumans'],
37
                'direwolves' => [Characters::class, 'getDirewolves'],
38
            ],
39
            'Character' => [
40
                self::RESOLVE_TYPE => function ($value) {
41
                    return Characters::TYPE_HUMAN === $value['type'] ? 'Human' : 'Direwolf';
42
                },
43
            ],
44
            'Human' => [
45
                'direwolf' => function ($value) {
46
                    $direwolves = Characters::getDirewolves();
47
                    if (isset($direwolves[$value['direwolf']])) {
48
                        return $direwolves[$value['direwolf']];
49
                    } else {
50
                        return null;
51
                    }
52
                },
53
            ],
54
            // enum internal values
55
            'Status' => [
56
                'ALIVE' => 1,
57
                'DECEASED' => 0,
58
            ],
59
            // custom scalar
60
            'Year' => [
61
                self::SERIALIZE => function ($value) {
62
                    return sprintf('%s AC', $value);
63
                },
64
                self::PARSE_VALUE => function ($value) {
65
                    if (!is_string($value)) {
66
                        throw new Error(sprintf('Cannot represent following value as a valid year: %s.', Utils::printSafeJson($value)));
67
                    }
68
69
                    return (int) str_replace(' AC', '', $value);
70
                },
71
                self::PARSE_LITERAL => function ($valueNode) {
72
                    if (!$valueNode instanceof StringValueNode) {
73
                        throw new Error('Query error: Can only parse strings got: '.$valueNode->kind, [$valueNode]);
74
                    }
75
76
                    return (int) str_replace(' AC', '', $valueNode->value);
77
                },
78
            ],
79
        ];
80
    }
81
}
82