@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | 'bookId' => [ |
| 18 | 18 | 'type' => Type::id(), |
| 19 | 19 | 'errorCodes' => ['bookNotFound'], |
| 20 | - 'validate' => function ($bookId) { |
|
| 20 | + 'validate' => function($bookId) { |
|
| 21 | 21 | return 0; |
| 22 | 22 | }, |
| 23 | 23 | ], |
| 24 | 24 | ], |
| 25 | - 'resolve' => static function ($value, $args) : bool { |
|
| 25 | + 'resolve' => static function($value, $args) : bool { |
|
| 26 | 26 | return true; |
| 27 | 27 | }, |
| 28 | 28 | ]); |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | 'bookId' => [ |
| 40 | 40 | 'type' => Type::id(), |
| 41 | 41 | 'errorCodes' => ['bookNotFound'], |
| 42 | - 'validate' => function ($bookId) { |
|
| 42 | + 'validate' => function($bookId) { |
|
| 43 | 43 | return 0; |
| 44 | 44 | }, |
| 45 | 45 | ], |
| 46 | 46 | ], |
| 47 | - 'resolve' => static function ($value, $args) : bool { |
|
| 47 | + 'resolve' => static function($value, $args) : bool { |
|
| 48 | 48 | return true; |
| 49 | 49 | }, |
| 50 | 50 | ]); |
@@ -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); |