@@ -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']), |
@@ -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,17 +61,17 @@ 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 | - $config['type'] = new InputObjectType([ |
|
66 | + $config['type'] = new InputObjectType([ |
|
67 | 67 | 'name'=>'', |
68 | 68 | 'fields' => $args, |
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 | |
@@ -88,7 +88,7 @@ discard block |
||
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 | /** |
@@ -100,13 +100,13 @@ discard block |
||
100 | 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) { |
@@ -24,14 +24,14 @@ discard block |
||
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 | ]; |
@@ -173,7 +173,7 @@ discard block |
||
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': |
@@ -71,7 +71,7 @@ |
||
71 | 71 | 'fields' => [ |
72 | 72 | 'authorId' => [ |
73 | 73 | 'errorCodes' => ['unknownAuthor'], |
74 | - 'validate' => static function (int $authorId) { |
|
74 | + 'validate' => static function(int $authorId) { |
|
75 | 75 | return $authorId ? 0 : 1; |
76 | 76 | }, |
77 | 77 | 'type' => Type::id(), |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | 'title' => [ |
63 | 63 | 'type' => Type::string(), |
64 | 64 | 'description' => 'Enter a book title, no more than 10 characters in length', |
65 | - 'validate' => static function (string $title) { |
|
65 | + 'validate' => static function(string $title) { |
|
66 | 66 | if (strlen($title) > 10) { |
67 | 67 | return [1, 'book title must be less than 10 chaacters']; |
68 | 68 | } |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | 'unknownAuthor', |
77 | 77 | 'authorDeceased', |
78 | 78 | ], |
79 | - 'validate' => function (string $authorId) { |
|
80 | - if (! isset($this->data['people'][$authorId])) { |
|
79 | + 'validate' => function(string $authorId) { |
|
80 | + if (!isset($this->data['people'][$authorId])) { |
|
81 | 81 | return ['unknownAuthor', 'We have no record of that author']; |
82 | 82 | } |
83 | 83 | return 0; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | 'query' => $this->query, |
93 | 93 | 'mutation' => new ObjectType([ |
94 | 94 | 'name' => 'Mutation', |
95 | - 'fields' => function () { |
|
95 | + 'fields' => function() { |
|
96 | 96 | return [ |
97 | 97 | 'updateBooks' => new ValidatedFieldDefinition([ |
98 | 98 | 'name' => 'updateBooks', |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | 'args' => [ |
101 | 101 | 'bookAttributes' => [ |
102 | 102 | 'type' => Type::listOf($this->bookAttributesInputType), |
103 | - 'validate' => static function ($var) { |
|
104 | - return $var ? 0: 1; |
|
103 | + 'validate' => static function($var) { |
|
104 | + return $var ? 0 : 1; |
|
105 | 105 | }, |
106 | - 'validateItem' => static function ($book) { |
|
107 | - return isset($book['author']) || isset($book['title']) ? 0: 1; |
|
106 | + 'validateItem' => static function($book) { |
|
107 | + return isset($book['author']) || isset($book['title']) ? 0 : 1; |
|
108 | 108 | }, |
109 | 109 | ], |
110 | 110 | ], |
111 | - 'resolve' => static function ($value) : bool { |
|
112 | - return ! ! $value; |
|
111 | + 'resolve' => static function($value) : bool { |
|
112 | + return !!$value; |
|
113 | 113 | }, |
114 | 114 | ]), |
115 | 115 | ]; |
@@ -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 | ], |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | 'bookId' => [ |
18 | 18 | 'type' => Type::id(), |
19 | 19 | 'errorCodes' => ['bookNotFound'], |
20 | - 'validate' => static function ($bookId) { |
|
20 | + 'validate' => static function($bookId) { |
|
21 | 21 | return $bookId ? 0 : 1; |
22 | 22 | }, |
23 | 23 | ], |
24 | 24 | ], |
25 | - 'resolve' => static function ($value) : bool { |
|
26 | - return ! ! $value; |
|
25 | + 'resolve' => static function($value) : bool { |
|
26 | + return !!$value; |
|
27 | 27 | }, |
28 | 28 | ]); |
29 | 29 | |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | 'bookId' => [ |
40 | 40 | 'type' => Type::id(), |
41 | 41 | 'errorCodes' => ['bookNotFound'], |
42 | - 'validate' => static function ($bookId) { |
|
42 | + 'validate' => static function($bookId) { |
|
43 | 43 | return $bookId ? 0 : 1; |
44 | 44 | }, |
45 | 45 | ], |
46 | 46 | ], |
47 | - 'resolve' => static function ($value) : bool { |
|
48 | - return ! ! $value; |
|
47 | + 'resolve' => static function($value) : bool { |
|
48 | + return !!$value; |
|
49 | 49 | }, |
50 | 50 | ]); |
51 | 51 |
@@ -19,14 +19,14 @@ discard block |
||
19 | 19 | { |
20 | 20 | $types = []; |
21 | 21 | new UserErrorsType([ |
22 | - 'validate' => static function ($val) { |
|
22 | + 'validate' => static function($val) { |
|
23 | 23 | return $val ? 0 : 1; |
24 | 24 | }, |
25 | 25 | 'errorCodes' => [ |
26 | 26 | 'unknownUser', |
27 | 27 | 'userIsMinor', |
28 | 28 | ], |
29 | - 'typeSetter' => static function ($type) use (&$types) { |
|
29 | + 'typeSetter' => static function($type) use (&$types) { |
|
30 | 30 | $types[$type->name] = $type; |
31 | 31 | }, |
32 | 32 | 'type' => new IDType(['name' => 'User']), |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | ], |
60 | 60 | ], |
61 | 61 | ]), |
62 | - 'typeSetter' => static function ($type) use (&$types) { |
|
62 | + 'typeSetter' => static function($type) use (&$types) { |
|
63 | 63 | $types[$type->name] = $type; |
64 | 64 | }, |
65 | 65 | ], ['updateBook']); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | 'name' => 'bookInput', |
82 | 82 | 'fields' => [ |
83 | 83 | 'authorId' => [ |
84 | - 'validate' => static function ($authorId) { |
|
84 | + 'validate' => static function($authorId) { |
|
85 | 85 | return $authorId ? 0 : 1; |
86 | 86 | }, |
87 | 87 | 'errorCodes' => ['unknownAuthor'], |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | ], |
91 | 91 | ], |
92 | 92 | ]), |
93 | - 'typeSetter' => static function ($type) use (&$types) { |
|
93 | + 'typeSetter' => static function($type) use (&$types) { |
|
94 | 94 | $types[$type->name] = $type; |
95 | 95 | }, |
96 | 96 | ], ['updateBook']); |
@@ -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', |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | 'bookAttributes' => [ |
101 | 101 | 'type' => $this->bookAttributesInputType, |
102 | 102 | 'errorCodes' => ['titleOrIdRequired'], |
103 | - 'validate' => static function (?array $bookAttributes) { |
|
103 | + 'validate' => static function(?array $bookAttributes) { |
|
104 | 104 | if (!$bookAttributes) { |
105 | 105 | return 0; |
106 | 106 | } |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | }, |
113 | 113 | ], |
114 | 114 | ], |
115 | - 'resolve' => static function ($value, $args) : bool { |
|
115 | + 'resolve' => static function($value, $args) : bool { |
|
116 | 116 | // ... |
117 | 117 | // do update |
118 | 118 | // ... |
119 | 119 | |
120 | - return ! $value; |
|
120 | + return !$value; |
|
121 | 121 | }, |
122 | 122 | ]), |
123 | 123 | ]; |