1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overblog\GraphQLBundle\Config; |
4
|
|
|
|
5
|
|
|
use Overblog\GraphQLBundle\DependencyInjection\Configuration; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7
|
|
|
|
8
|
|
|
abstract class TypeDefinition |
9
|
|
|
{ |
10
|
|
|
abstract public function getDefinition(); |
11
|
|
|
|
12
|
37 |
|
protected function __construct() |
13
|
|
|
{ |
14
|
37 |
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @return static |
18
|
|
|
*/ |
19
|
37 |
|
public static function create() |
20
|
|
|
{ |
21
|
37 |
|
return new static(); |
22
|
|
|
} |
23
|
|
|
|
24
|
37 |
|
protected function resolveTypeSection() |
25
|
|
|
{ |
26
|
37 |
|
$node = self::createNode('resolveType', 'variable'); |
27
|
|
|
|
28
|
37 |
|
return $node; |
29
|
|
|
} |
30
|
|
|
|
31
|
37 |
|
protected function nameSection() |
32
|
|
|
{ |
33
|
37 |
|
$node = self::createNode('name', 'scalar'); |
34
|
37 |
|
$node->isRequired(); |
35
|
37 |
|
$node->validate() |
36
|
|
|
->ifTrue(function ($name) { |
37
|
32 |
|
return !\preg_match('/^[_a-z][_0-9a-z]*$/i', $name); |
38
|
37 |
|
}) |
39
|
37 |
|
->thenInvalid('Invalid type name "%s". (see https://facebook.github.io/graphql/October2016/#Name)') |
40
|
37 |
|
->end(); |
41
|
|
|
|
42
|
37 |
|
return $node; |
43
|
|
|
} |
44
|
|
|
|
45
|
37 |
|
protected function defaultValueSection() |
46
|
|
|
{ |
47
|
37 |
|
$node = self::createNode('defaultValue', 'variable'); |
48
|
|
|
|
49
|
37 |
|
return $node; |
50
|
|
|
} |
51
|
|
|
|
52
|
37 |
|
protected function descriptionSection() |
53
|
|
|
{ |
54
|
37 |
|
$node = self::createNode('description', 'scalar'); |
55
|
|
|
|
56
|
37 |
|
return $node; |
57
|
|
|
} |
58
|
|
|
|
59
|
37 |
|
protected function deprecationReasonSelection() |
60
|
|
|
{ |
61
|
37 |
|
$node = self::createNode('deprecationReason', 'scalar'); |
62
|
|
|
|
63
|
37 |
|
$node->info('Text describing why this field is deprecated. When not empty - field will not be returned by introspection queries (unless forced)'); |
64
|
|
|
|
65
|
37 |
|
return $node; |
66
|
|
|
} |
67
|
|
|
|
68
|
37 |
|
protected function typeSelection($isRequired = false) |
69
|
|
|
{ |
70
|
37 |
|
$node = self::createNode('type', 'scalar'); |
71
|
|
|
|
72
|
37 |
|
$node->info('One of internal or custom types.'); |
73
|
|
|
|
74
|
37 |
|
if ($isRequired) { |
75
|
37 |
|
$node->isRequired(); |
76
|
|
|
} |
77
|
|
|
|
78
|
37 |
|
return $node; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @internal |
83
|
|
|
* |
84
|
|
|
* @param string $name |
85
|
|
|
* @param string $type |
86
|
|
|
* |
87
|
|
|
* @return \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition|\Symfony\Component\Config\Definition\Builder\NodeDefinition |
88
|
|
|
*/ |
89
|
37 |
|
protected static function createNode($name, $type = 'array') |
90
|
|
|
{ |
91
|
37 |
|
return Configuration::getRootNodeWithoutDeprecation(new TreeBuilder($name, $type), $name, $type); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.