@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | final class ListOfTest extends TestCase |
17 | 17 | { |
18 | - public function testScalarTypeWithNoValidation() |
|
18 | + public function testScalarTypeWithNoValidation () |
|
19 | 19 | { |
20 | 20 | $type = new UserErrorsType([ |
21 | 21 | 'type' => Type::listOf(Type::id()), |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | '), SchemaPrinter::doPrint(new Schema(['query' => $type]))); |
35 | 35 | } |
36 | 36 | |
37 | - public function testListOfScalarWithValidationOnSelf() |
|
37 | + public function testListOfScalarWithValidationOnSelf () |
|
38 | 38 | { |
39 | 39 | $type = new UserErrorsType([ |
40 | 40 | 'type' => Type::listOf(Type::id()), |
41 | 41 | 'errorCodes'=> ['atLeastOneRequired'], |
42 | - 'validate' => static function ($value) { |
|
42 | + 'validate' => static function($value) { |
|
43 | 43 | return $value ? 0 : 1; |
44 | 44 | }, |
45 | 45 | ], ['users']); |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | '), SchemaPrinter::doPrint(new Schema(['query' => $type]))); |
67 | 67 | } |
68 | 68 | |
69 | - public function testListOfListOfListOfScalarWithValidationOnSelfAndWrappedType() |
|
69 | + public function testListOfListOfListOfScalarWithValidationOnSelfAndWrappedType () |
|
70 | 70 | { |
71 | 71 | $type = new UserErrorsType([ |
72 | 72 | 'type' => Type::listOf(Type::listOf(Type::listOf(Type::id()))), |
73 | 73 | 'errorCodes'=> ['atLeastOneRequired'], |
74 | - 'validate' => static function ($value) { |
|
74 | + 'validate' => static function($value) { |
|
75 | 75 | return $value ? 0 : 1; |
76 | 76 | }, |
77 | - 'validateItem' => static function ($value) { |
|
77 | + 'validateItem' => static function($value) { |
|
78 | 78 | return $value ? 0 : 1; |
79 | 79 | }, |
80 | 80 | ], ['users']); |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | '), SchemaPrinter::doPrint(new Schema(['query' => $type]))); |
117 | 117 | } |
118 | 118 | |
119 | - public function testListOfInputObjectWithValidationOnSelf() |
|
119 | + public function testListOfInputObjectWithValidationOnSelf () |
|
120 | 120 | { |
121 | 121 | $type = new UserErrorsType([ |
122 | - 'validate' => static function (array $authors) { |
|
122 | + 'validate' => static function(array $authors) { |
|
123 | 123 | if (count($authors) < 1) { |
124 | 124 | return ['atLeastOneAuthorRequired', 'You must submit at least one author']; |
125 | 125 | } |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | '), SchemaPrinter::doPrint(new Schema(['query' => $type]))); |
161 | 161 | } |
162 | 162 | |
163 | - public function testListOfInputObjectWithValidationOnWrappedSelf() |
|
163 | + public function testListOfInputObjectWithValidationOnWrappedSelf () |
|
164 | 164 | { |
165 | 165 | $type = new UserErrorsType([ |
166 | 166 | 'suberrorCodes' => ['firstNameOrLastNameRequired'], |
167 | - 'validateItem' => static function (array $author) { |
|
168 | - if (! isset($author['firstName']) && ! isset($author['lastName'])) { |
|
167 | + 'validateItem' => static function(array $author) { |
|
168 | + if (!isset($author['firstName']) && !isset($author['lastName'])) { |
|
169 | 169 | return ['atLeastOneAuthorRequired', 'You must submit a first name or a last name']; |
170 | 170 | } |
171 | 171 | }, |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | 'fields' => [ |
175 | 175 | 'firstName' => [ |
176 | 176 | 'type' => Type::string(), |
177 | - 'validate' => static function (string $name) { |
|
177 | + 'validate' => static function(string $name) { |
|
178 | 178 | return $name ? 0 : 1; |
179 | 179 | }, |
180 | 180 | ], |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | final class BasicTest extends TestCase |
15 | 15 | { |
16 | - public function testNoValidationOnSelf() |
|
16 | + public function testNoValidationOnSelf () |
|
17 | 17 | { |
18 | 18 | $type = new UserErrorsType([ |
19 | 19 | 'type' => Type::id(), |
@@ -32,20 +32,20 @@ discard block |
||
32 | 32 | '), SchemaPrinter::doPrint(new Schema(['query' => $type]))); |
33 | 33 | } |
34 | 34 | |
35 | - public function testNoType() |
|
35 | + public function testNoType () |
|
36 | 36 | { |
37 | 37 | $this->expectExceptionMessage('You must specify a type for your field'); |
38 | 38 | UserErrorsType::create([ |
39 | - 'validate' => static function ($value) { |
|
39 | + 'validate' => static function($value) { |
|
40 | 40 | return $value ? 0 : 1; |
41 | 41 | }, |
42 | 42 | ], ['upsertSku']); |
43 | 43 | } |
44 | 44 | |
45 | - public function testValidationWithNoErrorCodes() |
|
45 | + public function testValidationWithNoErrorCodes () |
|
46 | 46 | { |
47 | 47 | $type = UserErrorsType::create([ |
48 | - 'validate' => static function ($value) { |
|
48 | + 'validate' => static function($value) { |
|
49 | 49 | return $value ? 0 : 1; |
50 | 50 | }, |
51 | 51 | 'type' => Type::id(), |
@@ -13,7 +13,7 @@ |
||
13 | 13 | |
14 | 14 | /** @var mixed */ |
15 | 15 | public $error; |
16 | - public function __construct($path, $error) |
|
16 | + public function __construct ($path, $error) |
|
17 | 17 | { |
18 | 18 | parent::__construct(); |
19 | 19 | $this->path = $path; |
@@ -20,18 +20,18 @@ discard block |
||
20 | 20 | * @param mixed[] $config |
21 | 21 | * @param string[] $path |
22 | 22 | */ |
23 | - public function __construct(array $config, array $path, $isParentList = false) |
|
23 | + public function __construct (array $config, array $path, $isParentList = false) |
|
24 | 24 | { |
25 | 25 | $finalFields = $config['fields'] ?? []; |
26 | 26 | |
27 | - if (! isset($config['type'])) { |
|
27 | + if (!isset($config['type'])) { |
|
28 | 28 | throw new Exception('You must specify a type for your field'); |
29 | 29 | } |
30 | 30 | |
31 | 31 | GraphQL\Utils\Utils::invariant($config['type'] instanceof Type, 'Must provide type.'); |
32 | 32 | |
33 | 33 | if (isset($config['errorCodes'])) { |
34 | - if (! isset($config['validate'])) { |
|
34 | + if (!isset($config['validate'])) { |
|
35 | 35 | throw new Exception('If you specify errorCodes, you must also provide a validate callback'); |
36 | 36 | } |
37 | 37 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | 'values' => $config['errorCodes'], |
44 | 44 | ]), $config), |
45 | 45 | 'description' => 'An error code', |
46 | - 'resolve' => static function ($value) { |
|
46 | + 'resolve' => static function($value) { |
|
47 | 47 | return $value['error'][0] ?? null; |
48 | 48 | }, |
49 | 49 | ]; |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $finalFields['msg'] = [ |
55 | 55 | 'type' => Type::string(), |
56 | 56 | 'description' => 'A natural language description of the issue', |
57 | - 'resolve' => static function ($value) { |
|
57 | + 'resolve' => static function($value) { |
|
58 | 58 | return $value['error'][1] ?? null; |
59 | 59 | }, |
60 | 60 | ]; |
@@ -65,18 +65,18 @@ discard block |
||
65 | 65 | $fields = []; |
66 | 66 | foreach ($type->getFields() as $key => $field) { |
67 | 67 | $newType = static::create( |
68 | - $field->config + ['typeSetter' => $config['typeSetter'] ?? null], |
|
68 | + $field->config+['typeSetter' => $config['typeSetter'] ?? null], |
|
69 | 69 | array_merge($path, [$key]) |
70 | 70 | ); |
71 | 71 | |
72 | - if (! $newType) { |
|
72 | + if (!$newType) { |
|
73 | 73 | continue; |
74 | 74 | } |
75 | 75 | |
76 | 76 | $fields[$key] = [ |
77 | 77 | 'description' => 'Error for ' . $key, |
78 | 78 | 'type' => $newType, |
79 | - 'resolve' => static function ($value) use ($key) { |
|
79 | + 'resolve' => static function($value) use ($key) { |
|
80 | 80 | return $value[$key] ?? null; |
81 | 81 | }, |
82 | 82 | ]; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | 'fields' => $fields, |
94 | 94 | ]), $config), |
95 | 95 | 'description' => 'Suberrors for ' . ucfirst($path[count($path)-1]), |
96 | - 'resolve' => static function (array $value) { |
|
96 | + 'resolve' => static function(array $value) { |
|
97 | 97 | return $value['suberrors'] ?? null; |
98 | 98 | }, |
99 | 99 | ]; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $finalFields['suberrors'] = [ |
118 | 118 | 'description' => 'Suberrors for the list of ' . $type->ofType . ' items', |
119 | 119 | 'type' => $newType, |
120 | - 'resolve' => static function ($value) { |
|
120 | + 'resolve' => static function($value) { |
|
121 | 121 | return $value['suberrors'] ?? null; |
122 | 122 | }, |
123 | 123 | ]; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $finalFields['path'] = [ |
132 | 132 | 'type' => Type::listOf(Type::int()), |
133 | 133 | 'description' => 'A path describing this items\'s location in the nested array', |
134 | - 'resolve' => static function ($value) { |
|
134 | + 'resolve' => static function($value) { |
|
135 | 135 | return $value['path']; |
136 | 136 | }, |
137 | 137 | ]; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @return mixed |
151 | 151 | */ |
152 | - protected function _set(Type $type, array $config) |
|
152 | + protected function _set (Type $type, array $config) |
|
153 | 153 | { |
154 | 154 | if (is_callable($config['typeSetter'] ?? null)) { |
155 | 155 | $config['typeSetter']($type); |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @throws Exception |
168 | 168 | */ |
169 | - public static function create(array $config, array $path, bool $isParentList = false, $name = '') : ?self |
|
169 | + public static function create (array $config, array $path, bool $isParentList = false, $name = '') : ?self |
|
170 | 170 | { |
171 | 171 | $config['fields'] = $config['fields'] ?? []; |
172 | 172 | if (isset($config['validate']) && is_callable($config['validate'])) { |
173 | 173 | $config['fields']['code'] = $config['fields']['code'] ?? [ |
174 | 174 | 'type' => Type::int(), |
175 | 175 | 'description' => 'A numeric error code. 0 on success, non-zero on failure.', |
176 | - 'resolve' => static function ($value) { |
|
176 | + 'resolve' => static function($value) { |
|
177 | 177 | $error = $value['error'] ?? null; |
178 | 178 | switch (gettype($error)) { |
179 | 179 | case 'integer': |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $config['fields']['msg'] = $config['fields']['msg'] ?? [ |
187 | 187 | 'type' => Type::string(), |
188 | 188 | 'description' => 'An error message.', |
189 | - 'resolve' => static function ($value) { |
|
189 | + 'resolve' => static function($value) { |
|
190 | 190 | $error = $value['error'] ?? null; |
191 | 191 | switch (gettype($error)) { |
192 | 192 | case 'integer': |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | /** |
212 | 212 | * @param string[] $path |
213 | 213 | */ |
214 | - protected function _nameFromPath(array $path) : string |
|
214 | + protected function _nameFromPath (array $path) : string |
|
215 | 215 | { |
216 | 216 | return implode('_', array_map('ucfirst', $path)); |
217 | 217 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @param mixed[] $config |
26 | 26 | */ |
27 | - public function __construct($config) |
|
27 | + public function __construct ($config) |
|
28 | 28 | { |
29 | 29 | $args = $config['args']; |
30 | 30 | $name = $config['name'] ?? lcfirst($this->tryInferName()); |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | 'result' => [ |
38 | 38 | 'type' => $config['type'], |
39 | 39 | 'description' => 'The payload, if any', |
40 | - 'resolve' => static function ($value) { |
|
40 | + 'resolve' => static function($value) { |
|
41 | 41 | return $value['result'] ?? null; |
42 | 42 | }, |
43 | 43 | ], |
44 | 44 | 'valid' => [ |
45 | 45 | 'type' => Type::nonNull(Type::boolean()), |
46 | 46 | 'description' => 'Whether all validation passed. True for yes, false for no.', |
47 | - 'resolve' => static function ($value) { |
|
47 | + 'resolve' => static function($value) { |
|
48 | 48 | return $value['valid']; |
49 | 49 | }, |
50 | 50 | ], |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | 'type' => $type, |
62 | 62 | 'args' => $args, |
63 | 63 | 'name' => $name, |
64 | - 'resolve' => function ($value, $args1, $context, $info) use ($config, $args) { |
|
64 | + 'resolve' => function($value, $args1, $context, $info) use ($config, $args) { |
|
65 | 65 | // validate inputs |
66 | 66 | $config['type'] = new InputObjectType([ |
67 | 67 | 'name'=>'', |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | ]); |
70 | 70 | $errors = $this->_validate($config, $args1); |
71 | 71 | $result = $errors; |
72 | - $result['valid'] = ! $errors; |
|
72 | + $result['valid'] = !$errors; |
|
73 | 73 | |
74 | - if (! isset($result['error']) && ! isset($result['suberrors'])) { |
|
74 | + if (!isset($result['error']) && !isset($result['suberrors'])) { |
|
75 | 75 | $result['result'] = $config['resolve']($value, $args1, $context, $info); |
76 | 76 | } |
77 | 77 | |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * @param mixed[] $arr |
85 | 85 | */ |
86 | - protected function _isAssoc(array $arr) : bool |
|
86 | + protected function _isAssoc (array $arr) : bool |
|
87 | 87 | { |
88 | 88 | if ($arr === []) { |
89 | 89 | return false; |
90 | 90 | } |
91 | - return array_keys($arr) !== range(0, count($arr) - 1); |
|
91 | + return array_keys($arr) !== range(0, count($arr)-1); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -97,16 +97,16 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @throws ValidateItemsError |
99 | 99 | */ |
100 | - protected function _validateItems(array $value, array $path, callable $validate) |
|
100 | + protected function _validateItems (array $value, array $path, callable $validate) |
|
101 | 101 | { |
102 | 102 | foreach ($value as $idx => $subValue) { |
103 | - if (is_array($subValue) && ! $this->_isAssoc($subValue)) { |
|
103 | + if (is_array($subValue) && !$this->_isAssoc($subValue)) { |
|
104 | 104 | $path[count($path)-1] = $idx; |
105 | 105 | $newPath = $path; |
106 | 106 | $newPath[] = 0; |
107 | 107 | $this->_validateItems($subValue, $newPath, $validate); |
108 | 108 | } else { |
109 | - $path[count($path) - 1] = $idx; |
|
109 | + $path[count($path)-1] = $idx; |
|
110 | 110 | $err = $validate($subValue); |
111 | 111 | |
112 | 112 | if ($err) { |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | /** |
120 | 120 | * @return mixed[] |
121 | 121 | */ |
122 | - protected function _validate($arg, $value) |
|
122 | + protected function _validate ($arg, $value) |
|
123 | 123 | { |
124 | 124 | $res = []; |
125 | 125 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * |
188 | 188 | * @throws ReflectionException |
189 | 189 | */ |
190 | - protected function tryInferName() |
|
190 | + protected function tryInferName () |
|
191 | 191 | { |
192 | 192 | // If class is extended - infer name from className |
193 | 193 | // QueryType -> Type |