@@ -29,38 +29,38 @@ |
||
29 | 29 | |
30 | 30 | abstract class AbstractQueryVisitor { |
31 | 31 | |
32 | - /** |
|
33 | - * @var int initial value of $this->memo |
|
34 | - */ |
|
35 | - protected $initialValue = 0; |
|
32 | + /** |
|
33 | + * @var int initial value of $this->memo |
|
34 | + */ |
|
35 | + protected $initialValue = 0; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var mixed the accumulator |
|
39 | - */ |
|
40 | - protected $memo; |
|
37 | + /** |
|
38 | + * @var mixed the accumulator |
|
39 | + */ |
|
40 | + protected $memo; |
|
41 | 41 | |
42 | - /** |
|
43 | - * AbstractQueryVisitor constructor. |
|
44 | - */ |
|
45 | - public function __construct() { |
|
42 | + /** |
|
43 | + * AbstractQueryVisitor constructor. |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | 46 | $this->memo = $this->initialValue; |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return mixed getter for the memo, in case callers want to inspect it after a process run |
|
51 | - */ |
|
52 | - public function getMemo() { |
|
49 | + /** |
|
50 | + * @return mixed getter for the memo, in case callers want to inspect it after a process run |
|
51 | + */ |
|
52 | + public function getMemo() { |
|
53 | 53 | return $this->memo; |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Visit a query node. See class docstring. |
|
58 | - * |
|
59 | - * @param array $args |
|
60 | - * @param FieldConfig $fieldConfig |
|
61 | - * @param int $childScore |
|
62 | - * |
|
63 | - * @return int|null |
|
64 | - */ |
|
65 | - abstract public function visit(array $args, FieldConfig $fieldConfig, $childScore = 0); |
|
56 | + /** |
|
57 | + * Visit a query node. See class docstring. |
|
58 | + * |
|
59 | + * @param array $args |
|
60 | + * @param FieldConfig $fieldConfig |
|
61 | + * @param int $childScore |
|
62 | + * |
|
63 | + * @return int|null |
|
64 | + */ |
|
65 | + abstract public function visit(array $args, FieldConfig $fieldConfig, $childScore = 0); |
|
66 | 66 | } |
67 | 67 | \ No newline at end of file |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | $authors = []; |
44 | 44 | while (count($authors) < rand(1, 4)) { |
45 | 45 | $authors[] = [ |
46 | - 'name' => 'Author ' . substr(md5(time()), 0, 4) |
|
46 | + 'name' => 'Author '.substr(md5(time()), 0, 4) |
|
47 | 47 | ]; |
48 | 48 | } |
49 | 49 | $data[] = [ |
50 | 50 | 'id' => $i, |
51 | - 'title' => 'Title of ' . $i, |
|
51 | + 'title' => 'Title of '.$i, |
|
52 | 52 | 'authors' => $authors, |
53 | 53 | ]; |
54 | 54 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | // return true; |
70 | 70 | $p->processPayload('{ posts { id, title, authors { name } } }'); |
71 | 71 | $res = $p->getResponseData(); |
72 | - echo "Count: " . count($res['data']['posts']) . "\n"; |
|
72 | + echo "Count: ".count($res['data']['posts'])."\n"; |
|
73 | 73 | printf("Test Time: %04f\n", microtime(true) - $time); |
74 | 74 | // $p->getResponseData(); |
75 | 75 | } |
@@ -9,13 +9,7 @@ discard block |
||
9 | 9 | namespace Youshido\Tests\Library\Type; |
10 | 10 | |
11 | 11 | |
12 | -use Youshido\GraphQL\Execution\Context\ExecutionContext; |
|
13 | 12 | use Youshido\GraphQL\Execution\Processor; |
14 | -use Youshido\GraphQL\Execution\Request; |
|
15 | -use Youshido\GraphQL\Field\Field; |
|
16 | -use Youshido\GraphQL\Parser\Ast\Argument; |
|
17 | -use Youshido\GraphQL\Parser\Ast\ArgumentValue\Literal; |
|
18 | -use Youshido\GraphQL\Parser\Ast\Query; |
|
19 | 13 | use Youshido\GraphQL\Schema\Schema; |
20 | 14 | use Youshido\GraphQL\Type\InputObject\InputObjectType; |
21 | 15 | use Youshido\GraphQL\Type\ListType\ListType; |
@@ -24,7 +18,6 @@ discard block |
||
24 | 18 | use Youshido\GraphQL\Type\Scalar\BooleanType; |
25 | 19 | use Youshido\GraphQL\Type\Scalar\StringType; |
26 | 20 | use Youshido\GraphQL\Type\TypeMap; |
27 | -use Youshido\GraphQL\Validator\ResolveValidator\ResolveValidator; |
|
28 | 21 | use Youshido\Tests\DataProvider\TestInputObjectType; |
29 | 22 | |
30 | 23 | class InputObjectTypeTest extends \PHPUnit_Framework_TestCase |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | 'fields' => [ |
61 | 61 | 'empty' => [ |
62 | 62 | 'type' => new StringType(), |
63 | - 'resolve' => function () { |
|
63 | + 'resolve' => function() { |
|
64 | 64 | return null; |
65 | 65 | } |
66 | 66 | ] |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | ])) |
80 | 80 | ], |
81 | 81 | 'type' => new BooleanType(), |
82 | - 'resolve' => function ($object, $args) { |
|
82 | + 'resolve' => function($object, $args) { |
|
83 | 83 | return true; |
84 | 84 | } |
85 | 85 | ] |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | 'fields' => [ |
101 | 101 | 'empty' => [ |
102 | 102 | 'type' => new StringType(), |
103 | - 'resolve' => function () { } |
|
103 | + 'resolve' => function() { } |
|
104 | 104 | ], |
105 | 105 | ] |
106 | 106 | ]), |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | ] |
123 | 123 | ]) |
124 | 124 | ], |
125 | - 'resolve' => function () { return 'success message'; } |
|
125 | + 'resolve' => function() { return 'success message'; } |
|
126 | 126 | ] |
127 | 127 | ] |
128 | 128 | ]) |
@@ -37,7 +37,9 @@ |
||
37 | 37 | if ($isValid && $itemType->isInputType()) { |
38 | 38 | foreach($value as $item) { |
39 | 39 | $isValid = $itemType->isValidValue($item); |
40 | - if (!$isValid) return false; |
|
40 | + if (!$isValid) { |
|
41 | + return false; |
|
42 | + } |
|
41 | 43 | } |
42 | 44 | } |
43 | 45 | return $isValid; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $isValid = is_null($value) || is_array($value) || $this->isIterableObject($value); |
36 | 36 | $itemType = $this->config->get('itemType'); |
37 | 37 | if ($isValid && $itemType->isInputType()) { |
38 | - foreach($value as $item) { |
|
38 | + foreach ($value as $item) { |
|
39 | 39 | $isValid = $itemType->isValidValue($item); |
40 | 40 | if (!$isValid) return false; |
41 | 41 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | private function isIterableObject($value) |
47 | 47 | { |
48 | - if(is_object($value)) { |
|
48 | + if (is_object($value)) { |
|
49 | 49 | $implements = class_implements($value); |
50 | 50 | return isset($implements['Iterator']) || isset($implements['IteratorAggregate']); |
51 | 51 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | if ($value && $value->getKind() == TypeMap::KIND_ENUM) { |
59 | 59 | $data = []; |
60 | 60 | foreach ($value->getValues() as $enumValue) { |
61 | - if(!$args['includeDeprecated'] && (isset($enumValue['isDeprecated']) && $enumValue['isDeprecated'])) { |
|
61 | + if (!$args['includeDeprecated'] && (isset($enumValue['isDeprecated']) && $enumValue['isDeprecated'])) { |
|
62 | 62 | continue; |
63 | 63 | } |
64 | 64 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** @var AbstractObjectType $value */ |
94 | - return array_filter($value->getConfig()->getFields(), function ($field) use ($args) { |
|
94 | + return array_filter($value->getConfig()->getFields(), function($field) use ($args) { |
|
95 | 95 | /** @var $field Field */ |
96 | 96 | if (in_array($field->getName(), ['__type', '__schema']) || (!$args['includeDeprecated'] && $field->isDeprecated())) { |
97 | 97 | return false; |
@@ -149,7 +149,9 @@ |
||
149 | 149 | { |
150 | 150 | $unionTypes = $unionType->getTypes(); |
151 | 151 | $valid = false; |
152 | - if (empty($unionTypes)) return false; |
|
152 | + if (empty($unionTypes)) { |
|
153 | + return false; |
|
154 | + } |
|
153 | 155 | |
154 | 156 | foreach ($unionTypes as $unionType) { |
155 | 157 | if ($unionType->getName() == $type->getName()) { |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @param AbstractObjectType $objectType |
48 | - * @param Mutation|Query|AstField $field |
|
48 | + * @param AstField $field |
|
49 | 49 | * |
50 | - * @return null |
|
50 | + * @return boolean |
|
51 | 51 | */ |
52 | 52 | public function objectHasField($objectType, $field) |
53 | 53 | { |
@@ -62,6 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @inheritdoc |
65 | + * @param Query $query |
|
65 | 66 | */ |
66 | 67 | public function validateArguments(FieldInterface $field, $query, Request $request) |
67 | 68 | { |
@@ -138,6 +139,9 @@ discard block |
||
138 | 139 | return true; |
139 | 140 | } |
140 | 141 | |
142 | + /** |
|
143 | + * @param Request $request |
|
144 | + */ |
|
141 | 145 | private function processInputObject(InputObject $astObject, AbstractInputObjectType $inputObjectType, $request) |
142 | 146 | { |
143 | 147 | foreach ($astObject->getValue() as $name => $value) { |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function validateArguments(FieldInterface $field, $query, Request $request) |
67 | 67 | { |
68 | - $requiredArguments = array_filter($field->getArguments(), function (InputField $argument) { |
|
68 | + $requiredArguments = array_filter($field->getArguments(), function(InputField $argument) { |
|
69 | 69 | return $argument->getType()->getKind() == TypeMap::KIND_NON_NULL; |
70 | 70 | }); |
71 | 71 | |
72 | - $withDefaultArguments = array_filter($field->getArguments(), function (InputField $argument) { |
|
72 | + $withDefaultArguments = array_filter($field->getArguments(), function(InputField $argument) { |
|
73 | 73 | return $argument->getConfig()->get('default') !== null; |
74 | 74 | }); |
75 | 75 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | foreach ($argument->getValue()->getValue() as $item) { |
97 | - if(!$this->processInputObject($item, $argumentType, $request)) { |
|
97 | + if (!$this->processInputObject($item, $argumentType, $request)) { |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | public function assertTypeImplementsInterface(AbstractType $type, AbstractInterfaceType $interface) |
187 | 187 | { |
188 | 188 | if (!$interface->isValidValue($type)) { |
189 | - throw new ResolveException('Type ' . $type->getName() . ' does not implement ' . $interface->getName()); |
|
189 | + throw new ResolveException('Type '.$type->getName().' does not implement '.$interface->getName()); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | } |
206 | 206 | |
207 | 207 | if (!$valid) { |
208 | - throw new ResolveException('Type ' . $type->getName() . ' not exist in types of ' . $unionType->getName()); |
|
208 | + throw new ResolveException('Type '.$type->getName().' not exist in types of '.$unionType->getName()); |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | 'description' => 'latest description', |
137 | 137 | 'deprecationReason' => 'for test', |
138 | 138 | 'isDeprecated' => true, |
139 | - 'resolve' => function () { |
|
139 | + 'resolve' => function() { |
|
140 | 140 | return [ |
141 | 141 | 'id' => 1, |
142 | 142 | 'name' => 'Alex' |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | ['name' => 'String', 'fields' => null], |
202 | 202 | ['name' => '__Schema', 'fields' => [['name' => 'queryType', 'args' => []], ['name' => 'mutationType', 'args' => []], ['name' => 'subscriptionType', 'args' => []], ['name' => 'types', 'args' => []], ['name' => 'directives', 'args' => []]]], |
203 | 203 | ['name' => '__Type', 'fields' => [['name' => 'name', 'args' => []], ['name' => 'kind', 'args' => []], ['name' => 'description', 'args' => []], ['name' => 'ofType', 'args' => []], ['name' => 'inputFields', 'args' => []], ['name' => 'enumValues', 'args' => [['defaultValue' => 'false']]], ['name' => 'fields', 'args' => [['defaultValue' => 'false']]], ['name' => 'interfaces', 'args' => []], ['name' => 'possibleTypes', 'args' => []]]], |
204 | - ['name' => '__InputValue', 'fields' => [['name' => 'name', 'args' => []], ['name' => 'description', 'args' => []], ['name' => 'type', 'args' => []], ['name' => 'defaultValue', 'args' => []],]], |
|
204 | + ['name' => '__InputValue', 'fields' => [['name' => 'name', 'args' => []], ['name' => 'description', 'args' => []], ['name' => 'type', 'args' => []], ['name' => 'defaultValue', 'args' => []], ]], |
|
205 | 205 | ['name' => 'Boolean', 'fields' => null], |
206 | - ['name' => '__EnumValue', 'fields' => [['name' => 'name', 'args' => []], ['name' => 'description', 'args' => []], ['name' => 'deprecationReason', 'args' => []], ['name' => 'isDeprecated', 'args' => []],]], |
|
206 | + ['name' => '__EnumValue', 'fields' => [['name' => 'name', 'args' => []], ['name' => 'description', 'args' => []], ['name' => 'deprecationReason', 'args' => []], ['name' => 'isDeprecated', 'args' => []], ]], |
|
207 | 207 | ['name' => '__Field', 'fields' => [['name' => 'name', 'args' => []], ['name' => 'description', 'args' => []], ['name' => 'isDeprecated', 'args' => []], ['name' => 'deprecationReason', 'args' => []], ['name' => 'type', 'args' => []], ['name' => 'args', 'args' => []]]], |
208 | 208 | ['name' => '__Subscription', 'fields' => [['name' => 'name', 'args' => []]]], |
209 | 209 | ['name' => '__Directive', 'fields' => [['name' => 'name', 'args' => []], ['name' => 'description', 'args' => []], ['name' => 'args', 'args' => []], ['name' => 'onOperation', 'args' => []], ['name' => 'onFragment', 'args' => []], ['name' => 'onField', 'args' => []]]], |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | 'id' => ['type' => new IntType()], |
292 | 292 | 'name' => ['type' => new IntType()], |
293 | 293 | ], |
294 | - 'resolveType' => function ($type) { |
|
294 | + 'resolveType' => function($type) { |
|
295 | 295 | |
296 | 296 | } |
297 | 297 | ]); |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | $unionType = new UnionType([ |
320 | 320 | 'name' => 'UnionType', |
321 | 321 | 'types' => [$object1, $object2], |
322 | - 'resolveType' => function () { |
|
322 | + 'resolveType' => function() { |
|
323 | 323 | |
324 | 324 | } |
325 | 325 | ]); |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | 'args' => [ |
331 | 331 | 'id' => ['type' => TypeMap::TYPE_INT] |
332 | 332 | ], |
333 | - 'resolve' => function () { |
|
333 | + 'resolve' => function() { |
|
334 | 334 | return [ |
335 | 335 | 'id' => 1, |
336 | 336 | 'name' => 'Alex' |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | ] |
357 | 357 | ]) |
358 | 358 | ], |
359 | - 'resolve' => function () { |
|
359 | + 'resolve' => function() { |
|
360 | 360 | return null; |
361 | 361 | } |
362 | 362 | ])); |
@@ -87,6 +87,9 @@ |
||
87 | 87 | return $this->getConfigValue('interfaces', []); |
88 | 88 | } |
89 | 89 | |
90 | + /** |
|
91 | + * @param ObjectType|null $value |
|
92 | + */ |
|
90 | 93 | public function isValidValue($value) |
91 | 94 | { |
92 | 95 | return is_array($value) || is_null($value) || is_object($value); |
@@ -34,7 +34,7 @@ |
||
34 | 34 | $config['type'] = $this->getType(); |
35 | 35 | $config['name'] = $this->getName(); |
36 | 36 | if (empty($config['name'])) { |
37 | - $config['name'] =$this->getAutoName(); |
|
37 | + $config['name'] = $this->getAutoName(); |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 |