@@ -22,7 +22,7 @@ |
||
22 | 22 | } |
23 | 23 | |
24 | 24 | // Toss out the first and last lines. |
25 | - $lines = array_slice($lines, 1, count($lines) - 2); |
|
25 | + $lines = array_slice($lines, 1, count($lines)-2); |
|
26 | 26 | |
27 | 27 | // take the tabs from the first line, and subtract them from all lines |
28 | 28 | $matches = []; |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $type = new UserErrorsType([ |
39 | 39 | 'type' => Type::listOf(Type::id()), |
40 | 40 | 'errorCodes'=> ['atLeastOneRequired'], |
41 | - 'validate' => static function ($value) { |
|
41 | + 'validate' => static function($value) { |
|
42 | 42 | return 0; |
43 | 43 | }, |
44 | 44 | ], ['users']); |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | $type = new UserErrorsType([ |
71 | 71 | 'type' => Type::listOf(Type::listOf(Type::listOf(Type::id()))), |
72 | 72 | 'errorCodes'=> ['atLeastOneRequired'], |
73 | - 'validate' => static function ($value) { |
|
73 | + 'validate' => static function($value) { |
|
74 | 74 | return 0; |
75 | 75 | }, |
76 | - 'validateItem' => static function ($value) { |
|
76 | + 'validateItem' => static function($value) { |
|
77 | 77 | return 0; |
78 | 78 | } |
79 | 79 | ], ['users']); |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | |
118 | 118 | public function testListOfInputObjectWithValidationOnSelf() |
119 | 119 | { |
120 | - $type = new UserErrorsType([ |
|
120 | + $type = new UserErrorsType([ |
|
121 | 121 | 'validate' => static function(array $authors) { |
122 | - if(count($authors) < 1) { |
|
122 | + if (count($authors) < 1) { |
|
123 | 123 | return ['atLeastOneAuthorRequired', "You must submit at least one author"]; |
124 | 124 | } |
125 | 125 | }, |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | |
162 | 162 | public function testListOfInputObjectWithValidationOnWrappedSelf() |
163 | 163 | { |
164 | - $type = new UserErrorsType([ |
|
164 | + $type = new UserErrorsType([ |
|
165 | 165 | 'suberrorCodes' => ['firstNameOrLastNameRequired'], |
166 | 166 | 'validateItem' => static function(array $author) { |
167 | - if(!isset($author['firstName']) && !isset($author['lastName'])) { |
|
167 | + if (!isset($author['firstName']) && !isset($author['lastName'])) { |
|
168 | 168 | return ['atLeastOneAuthorRequired', "You must submit a first name or a last name"]; |
169 | 169 | } |
170 | 170 | }, |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | 'query' => $this->query, |
32 | 32 | 'mutation' => new ObjectType([ |
33 | 33 | 'name' => 'Mutation', |
34 | - 'fields' => static function () { |
|
34 | + 'fields' => static function() { |
|
35 | 35 | return [ |
36 | 36 | 'setPhoneNumbers' => new ValidatedFieldDefinition([ |
37 | 37 | 'name' => 'setPhoneNumbers', |
@@ -40,20 +40,20 @@ discard block |
||
40 | 40 | 'phoneNumbers' => [ |
41 | 41 | 'type' => Type::listOf(Type::listOf(Type::string())), |
42 | 42 | 'errorCodes' => ['atLeastOneList'], |
43 | - 'validate' => static function (array $phoneNumberLists) { |
|
43 | + 'validate' => static function(array $phoneNumberLists) { |
|
44 | 44 | if (count($phoneNumberLists) < 1) { |
45 | 45 | return ['atLeastOneList', 'You must submit at least one list of numbers']; |
46 | 46 | } |
47 | 47 | return 0; |
48 | 48 | }, |
49 | 49 | 'suberrorCodes' => ['invalidPhoneNumber'], |
50 | - 'validateItem' => static function ($phoneNumber) { |
|
50 | + 'validateItem' => static function($phoneNumber) { |
|
51 | 51 | $res = preg_match('/^[0-9\-]+$/', $phoneNumber) === 1; |
52 | - return ! $res ? ['invalidPhoneNumber', 'That does not seem to be a valid phone number'] : 0; |
|
52 | + return !$res ? ['invalidPhoneNumber', 'That does not seem to be a valid phone number'] : 0; |
|
53 | 53 | }, |
54 | 54 | ], |
55 | 55 | ], |
56 | - 'resolve' => static function (array $phoneNumbers, $args) : bool { |
|
56 | + 'resolve' => static function(array $phoneNumbers, $args) : bool { |
|
57 | 57 | // ... |
58 | 58 | // stash them somewhere |
59 | 59 | // ... |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | [ |
111 | 111 | 'suberrors' => |
112 | 112 | [ |
113 | - 'path' => [0,1], |
|
113 | + 'path' => [0, 1], |
|
114 | 114 | 'code' => 'invalidPhoneNumber', |
115 | 115 | ] |
116 | 116 | ], |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | ); |
158 | 158 | |
159 | 159 | static::assertEquals( |
160 | - array ( |
|
160 | + array( |
|
161 | 161 | 'valid' => false, |
162 | 162 | 'suberrors' => |
163 | - array ( |
|
163 | + array( |
|
164 | 164 | 'phoneNumbers' => |
165 | - array ( |
|
165 | + array( |
|
166 | 166 | 'code' => 'atLeastOneList', |
167 | 167 | 'msg' => 'You must submit at least one list of numbers', |
168 | 168 | 'suberrors' => NULL, |
@@ -217,18 +217,18 @@ discard block |
||
217 | 217 | |
218 | 218 | static::assertEmpty($res->errors); |
219 | 219 | static::assertEquals( |
220 | - array ( |
|
220 | + array( |
|
221 | 221 | 'valid' => false, |
222 | 222 | 'suberrors' => |
223 | - array ( |
|
223 | + array( |
|
224 | 224 | 'phoneNumbers' => |
225 | - array ( |
|
225 | + array( |
|
226 | 226 | 'code' => NULL, |
227 | 227 | 'msg' => NULL, |
228 | 228 | 'suberrors' => |
229 | - array ( |
|
229 | + array( |
|
230 | 230 | 'path' => |
231 | - array ( |
|
231 | + array( |
|
232 | 232 | 0 => 1, |
233 | 233 | 1 => 1, |
234 | 234 | ), |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | 'title' => [ |
62 | 62 | 'type' => Type::string(), |
63 | 63 | 'description' => 'Enter a book title, no more than 10 characters in length', |
64 | - 'validate' => static function (string $title) { |
|
64 | + 'validate' => static function(string $title) { |
|
65 | 65 | if (strlen($title) > 10) { |
66 | 66 | return [1, 'book title must be less than 10 chaacters']; |
67 | 67 | } |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | 'unknownAuthor', |
76 | 76 | 'authorDeceased', |
77 | 77 | ], |
78 | - 'validate' => function (string $authorId) { |
|
79 | - if (! isset($this->data['people'][$authorId])) { |
|
78 | + 'validate' => function(string $authorId) { |
|
79 | + if (!isset($this->data['people'][$authorId])) { |
|
80 | 80 | return ['unknownAuthor', 'We have no record of that author']; |
81 | 81 | } |
82 | 82 | return 0; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | 'query' => $this->query, |
92 | 92 | 'mutation' => new ObjectType([ |
93 | 93 | 'name' => 'Mutation', |
94 | - 'fields' => function () { |
|
94 | + 'fields' => function() { |
|
95 | 95 | return [ |
96 | 96 | 'updateBook' => new ValidatedFieldDefinition([ |
97 | 97 | 'name' => 'updateBook', |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | 'titleOrIdRequired' |
104 | 104 | ], |
105 | 105 | 'validate' => static function(?array $bookAttributes) { |
106 | - if(is_null($bookAttributes)) { |
|
106 | + if (is_null($bookAttributes)) { |
|
107 | 107 | return 0; |
108 | 108 | } |
109 | 109 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | } |
114 | 114 | ], |
115 | 115 | ], |
116 | - 'resolve' => static function ($value, $args) : bool { |
|
116 | + 'resolve' => static function($value, $args) : bool { |
|
117 | 117 | // ... |
118 | 118 | // do update |
119 | 119 | // ... |
@@ -240,12 +240,12 @@ discard block |
||
240 | 240 | ); |
241 | 241 | |
242 | 242 | static::assertEquals( |
243 | - array ( |
|
243 | + array( |
|
244 | 244 | 'valid' => false, |
245 | 245 | 'suberrors' => |
246 | - array ( |
|
246 | + array( |
|
247 | 247 | 'bookAttributes' => |
248 | - array ( |
|
248 | + array( |
|
249 | 249 | 'code' => 'titleOrIdRequired', |
250 | 250 | 'msg' => 'You must supply at least one of title or author', |
251 | 251 | 'suberrors' => NULL, |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | |
352 | 352 | static::assertEmpty($res->errors); |
353 | 353 | static::assertEquals( |
354 | - array ( |
|
354 | + array( |
|
355 | 355 | 'valid' => true, |
356 | 356 | 'suberrors' => NULL, |
357 | 357 | 'result' => true, |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public function testNoType() { |
36 | 36 | $this->expectExceptionMessage("You must specify a type for your field"); |
37 | 37 | UserErrorsType::create([ |
38 | - 'validate' => static function ($value) { |
|
38 | + 'validate' => static function($value) { |
|
39 | 39 | } |
40 | 40 | ], ['upsertSku']); |
41 | 41 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | public function testValidationWithNoErrorCodes() |
44 | 44 | { |
45 | 45 | $type = UserErrorsType::create([ |
46 | - 'validate' => static function ($value) { |
|
46 | + 'validate' => static function($value) { |
|
47 | 47 | }, |
48 | 48 | 'type' => Type::id(), |
49 | 49 | ], ['upsertSku']); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | GraphQL\Utils\Utils::invariant($config['type'] instanceof Type, 'Must provide type.'); |
31 | 31 | |
32 | 32 | if (isset($config['errorCodes'])) { |
33 | - if(isset($config['validate'])) { |
|
33 | + if (isset($config['validate'])) { |
|
34 | 34 | /** code property */ |
35 | 35 | $finalFields['code'] = [ |
36 | 36 | 'type' => $this->_set(new EnumType([ |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | 'values' => $config['errorCodes'], |
40 | 40 | ]), $config), |
41 | 41 | 'description' => 'An error code', |
42 | - 'resolve' => static function ($value) { |
|
42 | + 'resolve' => static function($value) { |
|
43 | 43 | return $value['error'][0] ?? null; |
44 | 44 | }, |
45 | 45 | ]; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $finalFields['msg'] = [ |
51 | 51 | 'type' => Type::string(), |
52 | 52 | 'description' => 'A natural language description of the issue', |
53 | - 'resolve' => static function ($value) { |
|
53 | + 'resolve' => static function($value) { |
|
54 | 54 | return $value['error'][1] ?? null; |
55 | 55 | }, |
56 | 56 | ]; |
@@ -64,18 +64,18 @@ discard block |
||
64 | 64 | $fields = []; |
65 | 65 | foreach ($type->getFields() as $key => $field) { |
66 | 66 | $newType = static::create( |
67 | - $field->config + ['typeSetter' => $config['typeSetter'] ?? null], |
|
67 | + $field->config+['typeSetter' => $config['typeSetter'] ?? null], |
|
68 | 68 | array_merge($path, [$key]) |
69 | 69 | ); |
70 | 70 | |
71 | - if (! $newType) { |
|
71 | + if (!$newType) { |
|
72 | 72 | continue; |
73 | 73 | } |
74 | 74 | |
75 | 75 | $fields[$key] = [ |
76 | 76 | 'description' => 'Error for ' . $key, |
77 | 77 | 'type' => $newType, |
78 | - 'resolve' => static function ($value) use ($key) { |
|
78 | + 'resolve' => static function($value) use ($key) { |
|
79 | 79 | return $value[$key] ?? null; |
80 | 80 | }, |
81 | 81 | ]; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | 'fields' => $fields, |
93 | 93 | ]), $config), |
94 | 94 | 'description' => 'Suberrors for ' . ucfirst($path[count($path)-1]), |
95 | - 'resolve' => static function (array $value) { |
|
95 | + 'resolve' => static function(array $value) { |
|
96 | 96 | return $value['suberrors'] ?? null; |
97 | 97 | }, |
98 | 98 | ]; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $finalFields['suberrors'] = [ |
117 | 117 | 'description' => 'Suberrors for the list of ' . $type->ofType . ' items', |
118 | 118 | 'type' => $newType, |
119 | - 'resolve' => static function ($value) { |
|
119 | + 'resolve' => static function($value) { |
|
120 | 120 | return $value['suberrors'] ?? null; |
121 | 121 | }, |
122 | 122 | ]; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $finalFields['path'] = [ |
131 | 131 | 'type' => Type::listOf(Type::int()), |
132 | 132 | 'description' => 'A path describing this items\'s location in the nested array', |
133 | - 'resolve' => static function ($value) { |
|
133 | + 'resolve' => static function($value) { |
|
134 | 134 | return $value['path']; |
135 | 135 | }, |
136 | 136 | ]; |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $config['fields']['code'] = $config['fields']['code'] ?? [ |
168 | 168 | 'type' => Type::int(), |
169 | 169 | 'description' => 'A numeric error code. 0 on success, non-zero on failure.', |
170 | - 'resolve' => static function ($value) { |
|
170 | + 'resolve' => static function($value) { |
|
171 | 171 | $error = $value['error'] ?? null; |
172 | 172 | switch (gettype($error)) { |
173 | 173 | case 'integer': |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | $config['fields']['msg'] = $config['fields']['msg'] ?? [ |
181 | 181 | 'type' => Type::string(), |
182 | 182 | 'description' => 'An error message.', |
183 | - 'resolve' => static function ($value) { |
|
183 | + 'resolve' => static function($value) { |
|
184 | 184 | $error = $value['error'] ?? null; |
185 | 185 | switch (gettype($error)) { |
186 | 186 | case 'integer': |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | 'result' => [ |
35 | 35 | 'type' => $config['type'], |
36 | 36 | 'description' => 'The payload, if any', |
37 | - 'resolve' => static function ($value) { |
|
37 | + 'resolve' => static function($value) { |
|
38 | 38 | return $value['result'] ?? null; |
39 | 39 | }, |
40 | 40 | ], |
41 | 41 | 'valid' => [ |
42 | 42 | 'type' => Type::nonNull(Type::boolean()), |
43 | 43 | 'description' => 'Whether all validation passed. True for yes, false for no.', |
44 | - 'resolve' => static function ($value) { |
|
44 | + 'resolve' => static function($value) { |
|
45 | 45 | return $value['valid']; |
46 | 46 | }, |
47 | 47 | ], |
@@ -58,17 +58,17 @@ discard block |
||
58 | 58 | 'type' => $type, |
59 | 59 | 'args' => $args, |
60 | 60 | 'name' => $name, |
61 | - 'resolve' => function ($value, $args1, $context, $info) use ($config, $args) { |
|
61 | + 'resolve' => function($value, $args1, $context, $info) use ($config, $args) { |
|
62 | 62 | // validate inputs |
63 | - $config['type'] = new InputObjectType([ |
|
63 | + $config['type'] = new InputObjectType([ |
|
64 | 64 | 'name'=>'', |
65 | 65 | 'fields' => $args, |
66 | 66 | ]); |
67 | 67 | $errors = $this->_validate($config, $args1); |
68 | 68 | $result = $errors; |
69 | - $result['valid'] = ! $errors; |
|
69 | + $result['valid'] = !$errors; |
|
70 | 70 | |
71 | - if (! isset($result['error']) && ! isset($result['suberrors'])) { |
|
71 | + if (!isset($result['error']) && !isset($result['suberrors'])) { |
|
72 | 72 | $result['result'] = $config['resolve']($value, $args1, $context, $info); |
73 | 73 | } |
74 | 74 | |
@@ -80,19 +80,19 @@ discard block |
||
80 | 80 | protected function _isAssoc(array $arr) |
81 | 81 | { |
82 | 82 | if (array() === $arr) return false; |
83 | - return array_keys($arr) !== range(0, count($arr) - 1); |
|
83 | + return array_keys($arr) !== range(0, count($arr)-1); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | protected function _validateItems($value, array $path, callable $validate) { |
87 | 87 | foreach ($value as $idx => $subValue) { |
88 | - if(is_array($subValue) && !$this->_isAssoc($subValue)) { |
|
88 | + if (is_array($subValue) && !$this->_isAssoc($subValue)) { |
|
89 | 89 | $path[count($path)-1] = $idx; |
90 | 90 | $newPath = $path; |
91 | 91 | $newPath[] = 0; |
92 | 92 | $this->_validateItems($subValue, $newPath, $validate); |
93 | 93 | } |
94 | 94 | else { |
95 | - $path[count($path) - 1] = $idx; |
|
95 | + $path[count($path)-1] = $idx; |
|
96 | 96 | $err = $validate($subValue); |
97 | 97 | |
98 | 98 | if ($err) { |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
123 | - if(isset($arg['validateItem'])) { |
|
123 | + if (isset($arg['validateItem'])) { |
|
124 | 124 | try { |
125 | 125 | $this->_validateItems($value, [0], $arg['validateItem']); |
126 | 126 | } |
127 | - catch(ValidateItemsError $e) { |
|
127 | + catch (ValidateItemsError $e) { |
|
128 | 128 | $res['suberrors'] = [ |
129 | 129 | 'error' => $e->error, |
130 | 130 | 'path' => $e->path |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | } |
149 | 149 | |
150 | 150 | $fields = $type->getFields(); |
151 | - if(is_array($value)) { |
|
151 | + if (is_array($value)) { |
|
152 | 152 | foreach ($value as $key => $subValue) { |
153 | 153 | $config = $fields[$key]->config; |
154 | 154 | $res['suberrors'][$key] = $this->_validate($config, $subValue); |
@@ -37,7 +37,7 @@ |
||
37 | 37 | { |
38 | 38 | $type = new UserErrorsType([ |
39 | 39 | 'errorCodes' => ['invalidColor'], |
40 | - 'validate' => static function ($value) { |
|
40 | + 'validate' => static function($value) { |
|
41 | 41 | return $value ? 0 : 1; |
42 | 42 | }, |
43 | 43 | 'type' => new IDType(['name' => 'Color']), |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | { |
18 | 18 | public function testFieldsWithNoErrorCodes() |
19 | 19 | { |
20 | - $type = new UserErrorsType([ |
|
20 | + $type = new UserErrorsType([ |
|
21 | 21 | 'type' => new InputObjectType([ |
22 | 22 | 'name' => 'bookInput', |
23 | 23 | 'fields' => [ |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | public function testFieldsWithValidate() |
65 | 65 | { |
66 | - $type = new UserErrorsType([ |
|
66 | + $type = new UserErrorsType([ |
|
67 | 67 | 'type' => new InputObjectType([ |
68 | 68 | 'name' => 'bookInput', |
69 | 69 | 'fields' => [ |