GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

FieldArgument   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
wmc 16
eloc 56
dl 0
loc 109
ccs 30
cts 54
cp 0.5556
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A assertValid() 0 31 4
A getType() 0 3 1
B __construct() 0 22 7
A createMap() 0 11 3
A defaultValueExists() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Type\Definition;
6
7
use GraphQL\Error\InvariantViolation;
8
use GraphQL\Language\AST\InputValueDefinitionNode;
9
use GraphQL\Utils\Utils;
10
use function array_key_exists;
11
use function is_array;
12
use function is_string;
13
use function sprintf;
14
15
class FieldArgument
16
{
17
    /** @var string */
18
    public $name;
19
20
    /** @var mixed */
21
    public $defaultValue;
22
23
    /** @var string|null */
24
    public $description;
25
26
    /** @var InputValueDefinitionNode|null */
27
    public $astNode;
28
29
    /** @var mixed[] */
30
    public $config;
31
32
    /** @var InputType&Type */
33
    private $type;
34
35
    /**
36
     * @param mixed[] $def
37
     */
38 646
    public function __construct(array $def)
39
    {
40 646
        foreach ($def as $key => $value) {
41
            switch ($key) {
42 646
                case 'type':
43 646
                    $this->type = $value;
44 646
                    break;
45 646
                case 'name':
46 646
                    $this->name = $value;
47 646
                    break;
48 542
                case 'defaultValue':
49 476
                    $this->defaultValue = $value;
50 476
                    break;
51 129
                case 'description':
52 129
                    $this->description = $value;
53 129
                    break;
54 100
                case 'astNode':
55 100
                    $this->astNode = $value;
56 646
                    break;
57
            }
58
        }
59 646
        $this->config = $def;
60 646
    }
61
62
    /**
63
     * @param mixed[] $config
64
     *
65
     * @return FieldArgument[]
66
     */
67 715
    public static function createMap(array $config) : array
68
    {
69 715
        $map = [];
70 715
        foreach ($config as $name => $argConfig) {
71 637
            if (! is_array($argConfig)) {
72 11
                $argConfig = ['type' => $argConfig];
73
            }
74 637
            $map[] = new self($argConfig + ['name' => $name]);
75
        }
76
77 715
        return $map;
78
    }
79
80
    /**
81
     * @return InputType&Type
82
     */
83 909
    public function getType() : Type
84
    {
85 909
        return $this->type;
86
    }
87
88 337
    public function defaultValueExists() : bool
89
    {
90 337
        return array_key_exists('defaultValue', $this->config);
91
    }
92
93
    public function assertValid(FieldDefinition $parentField, Type $parentType)
94
    {
95
        try {
96
            Utils::assertValidName($this->name);
97
        } catch (InvariantViolation $e) {
98
            throw new InvariantViolation(
99
                sprintf('%s.%s(%s:) %s', $parentType->name, $parentField->name, $this->name, $e->getMessage())
100
            );
101
        }
102
        $type = $this->type;
103
        if ($type instanceof WrappingType) {
104
            $type = $type->getWrappedType(true);
105
        }
106
        Utils::invariant(
107
            $type instanceof InputType,
108
            sprintf(
109
                '%s.%s(%s): argument type must be Input Type but got: %s',
110
                $parentType->name,
111
                $parentField->name,
112
                $this->name,
113
                Utils::printSafe($this->type)
114
            )
115
        );
116
        Utils::invariant(
117
            $this->description === null || is_string($this->description),
118
            sprintf(
119
                '%s.%s(%s): argument description type must be string but got: %s',
120
                $parentType->name,
121
                $parentField->name,
122
                $this->name,
123
                Utils::printSafe($this->description)
124
            )
125
        );
126
    }
127
}
128