@@ -54,8 +54,8 @@ |
||
| 54 | 54 | protected function _getType($config) { |
| 55 | 55 | $type = $config['type']; |
| 56 | 56 | if (is_callable($type)) { |
| 57 | - $type = $type(); |
|
| 58 | - } |
|
| 57 | + $type = $type(); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | if ($type instanceof WrappingType) { |
| 61 | 61 | $type = $type->getWrappedType(true); |
@@ -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 |
@@ -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 |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | try { |
| 176 | 176 | $this->_validateItems($config, $value, [0], $config['validate'] ?? [$this, "_noop"]); |
| 177 | 177 | } catch (ValidateItemsError $e) { |
| 178 | - if(isset($e->error['suberrors'])) { |
|
| 178 | + if (isset($e->error['suberrors'])) { |
|
| 179 | 179 | $err = $e->error; |
| 180 | 180 | } |
| 181 | 181 | else { |
@@ -207,10 +207,10 @@ discard block |
||
| 207 | 207 | $fields = $type->getFields(); |
| 208 | 208 | if (is_array($value)) { |
| 209 | 209 | foreach ($value as $key => $subValue) { |
| 210 | - $config = $fields[$key]->config; |
|
| 210 | + $config = $fields[$key]->config; |
|
| 211 | 211 | $error = $this->_validate($config, $subValue); |
| 212 | 212 | |
| 213 | - if($error) { |
|
| 213 | + if ($error) { |
|
| 214 | 214 | $createSubErrors ? $res[UserErrorsType::SUBERRORS_NAME][$key] = $error : $res[$key] = $error; |
| 215 | 215 | } |
| 216 | 216 | } |