@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | |
37 | 37 | parent::__construct([ |
38 | 38 | 'type' => function() use($name, $config, $args) { |
39 | - return static::_create($name, $args, $config); |
|
40 | - }, |
|
39 | + return static::_create($name, $args, $config); |
|
40 | + }, |
|
41 | 41 | 'args' => $args, |
42 | 42 | 'name' => $name, |
43 | 43 | 'resolve' => function ($value, $args1, $context, $info) use ($config, $args) { |
@@ -62,33 +62,33 @@ discard block |
||
62 | 62 | } |
63 | 63 | |
64 | 64 | protected function _create($name, $args, $config) { |
65 | - return UserErrorsType::create([ |
|
66 | - 'errorCodes' => $config['errorCodes'] ?? null, |
|
67 | - 'isRoot' => true, |
|
68 | - 'fields' => [ |
|
69 | - $this->resultFieldName => [ |
|
70 | - 'type' => $config['type'], |
|
71 | - 'description' => 'The payload, if any', |
|
72 | - 'resolve' => static function ($value) { |
|
73 | - return $value['result'] ?? null; |
|
74 | - }, |
|
75 | - ], |
|
76 | - $this->validFieldName => [ |
|
77 | - 'type' => Type::nonNull(Type::boolean()), |
|
78 | - 'description' => 'Whether all validation passed. True for yes, false for no.', |
|
79 | - 'resolve' => static function ($value) { |
|
80 | - return $value['valid']; |
|
81 | - }, |
|
82 | - ], |
|
83 | - ], |
|
84 | - 'validate' => $config['validate'] ?? null, |
|
85 | - 'type' => new InputObjectType([ |
|
86 | - 'fields' => $args, |
|
87 | - 'name' => '', |
|
88 | - ]), |
|
89 | - 'typeSetter' => $config['typeSetter'] ?? null, |
|
90 | - ], [$name], false, ucfirst($name) . 'Result'); |
|
91 | - } |
|
65 | + return UserErrorsType::create([ |
|
66 | + 'errorCodes' => $config['errorCodes'] ?? null, |
|
67 | + 'isRoot' => true, |
|
68 | + 'fields' => [ |
|
69 | + $this->resultFieldName => [ |
|
70 | + 'type' => $config['type'], |
|
71 | + 'description' => 'The payload, if any', |
|
72 | + 'resolve' => static function ($value) { |
|
73 | + return $value['result'] ?? null; |
|
74 | + }, |
|
75 | + ], |
|
76 | + $this->validFieldName => [ |
|
77 | + 'type' => Type::nonNull(Type::boolean()), |
|
78 | + 'description' => 'Whether all validation passed. True for yes, false for no.', |
|
79 | + 'resolve' => static function ($value) { |
|
80 | + return $value['valid']; |
|
81 | + }, |
|
82 | + ], |
|
83 | + ], |
|
84 | + 'validate' => $config['validate'] ?? null, |
|
85 | + 'type' => new InputObjectType([ |
|
86 | + 'fields' => $args, |
|
87 | + 'name' => '', |
|
88 | + ]), |
|
89 | + 'typeSetter' => $config['typeSetter'] ?? null, |
|
90 | + ], [$name], false, ucfirst($name) . 'Result'); |
|
91 | + } |
|
92 | 92 | |
93 | 93 | private function _noop($value) { |
94 | 94 | // this is just a no-op validation function to fallback to when no validation function is provided |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $res = []; |
149 | 149 | |
150 | 150 | if (is_callable($arg['type'])) { |
151 | - $arg['type'] = $arg['type'](); |
|
151 | + $arg['type'] = $arg['type'](); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | $type = $arg['type']; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $this->resultFieldName = $config['resultName'] ?? 'result'; |
36 | 36 | |
37 | 37 | parent::__construct([ |
38 | - 'type' => function() use($name, $config, $args) { |
|
38 | + 'type' => function () use($name, $config, $args) { |
|
39 | 39 | return static::_create($name, $args, $config); |
40 | 40 | }, |
41 | 41 | 'args' => $args, |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | if ($arr === []) { |
104 | 104 | return false; |
105 | 105 | } |
106 | - return array_keys($arr) !== range(0, count($arr) - 1); |
|
106 | + return array_keys($arr) !== range(0, count($arr)-1); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | $path[count($path)-1] = $idx; |
120 | 120 | $newPath = $path; |
121 | 121 | $newPath[] = 0; |
122 | - $this->_validateItems($config, $subValue, $newPath, $validate ); |
|
122 | + $this->_validateItems($config, $subValue, $newPath, $validate); |
|
123 | 123 | } else { |
124 | - $path[count($path) - 1] = $idx; |
|
124 | + $path[count($path)-1] = $idx; |
|
125 | 125 | $err = $validate($subValue); |
126 | 126 | |
127 | - if(empty($err)) { |
|
127 | + if (empty($err)) { |
|
128 | 128 | $wrappedType = $config['type']->getWrappedType(true); |
129 | 129 | $err = $this->_validate([ |
130 | 130 | 'type' => $wrappedType |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $res = []; |
149 | 149 | |
150 | 150 | if (is_callable($arg['type'])) { |
151 | - $arg['type'] = $arg['type'](); |
|
151 | + $arg['type'] = $arg['type'](); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | $type = $arg['type']; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | try { |
180 | 180 | $this->_validateItems($config, $value, [0], $config['validate'] ?? [$this, "_noop"]); |
181 | 181 | } catch (ValidateItemsError $e) { |
182 | - if(isset($e->error['suberrors'])) { |
|
182 | + if (isset($e->error['suberrors'])) { |
|
183 | 183 | $err = $e->error; |
184 | 184 | } |
185 | 185 | else { |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | $fields = $type->getFields(); |
212 | 212 | if (is_array($value)) { |
213 | 213 | foreach ($value as $key => $subValue) { |
214 | - $config = $fields[$key]->config; |
|
214 | + $config = $fields[$key]->config; |
|
215 | 215 | $error = $this->_validate($config, $subValue); |
216 | 216 | |
217 | - if($error) { |
|
217 | + if ($error) { |
|
218 | 218 | $createSubErrors ? $res[UserErrorsType::SUBERRORS_NAME][$key] = $error : $res[$key] = $error; |
219 | 219 | } |
220 | 220 | } |