Passed
Pull Request — master (#1)
by Max
04:22
created
src/Type/Definition/UserErrorsType.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -26,33 +26,33 @@
 block discarded – undo
26 26
         GraphQL\Utils\Utils::invariant($config['type'] instanceof Type, 'Must provide type.');
27 27
 
28 28
         if (isset($config['errorCodes'])) {
29
-        	if(isset($config['validate'])) {
30
-		        /** code property */
31
-		        $finalFields['code'] = [
32
-			        'type' => $this->_set(new EnumType([
33
-				        'name' => $this->_nameFromPath(array_merge($path)) . 'ErrorCode',
34
-				        'description' => 'Error code',
35
-				        'values' => $config['errorCodes'],
36
-			        ]), $config),
37
-			        'description' => 'An error code',
38
-			        'resolve' => static function ($value) {
39
-				        return $value['error'][0] ?? null;
40
-			        },
41
-		        ];
42
-
43
-		        /**
44
-		         * msg property
45
-		         */
46
-		        $finalFields['msg'] = [
47
-			        'type' => Type::string(),
48
-			        'description' => 'A natural language description of the issue',
49
-			        'resolve' => static function ($value) {
50
-				        return $value['error'][1] ?? null;
51
-			        },
52
-		        ];
53
-	        } else {
54
-        		throw new \Exception("If you specify errorCodes, you must also provide a validate callback");
55
-	        }
29
+            if(isset($config['validate'])) {
30
+                /** code property */
31
+                $finalFields['code'] = [
32
+                    'type' => $this->_set(new EnumType([
33
+                        'name' => $this->_nameFromPath(array_merge($path)) . 'ErrorCode',
34
+                        'description' => 'Error code',
35
+                        'values' => $config['errorCodes'],
36
+                    ]), $config),
37
+                    'description' => 'An error code',
38
+                    'resolve' => static function ($value) {
39
+                        return $value['error'][0] ?? null;
40
+                    },
41
+                ];
42
+
43
+                /**
44
+                 * msg property
45
+                 */
46
+                $finalFields['msg'] = [
47
+                    'type' => Type::string(),
48
+                    'description' => 'A natural language description of the issue',
49
+                    'resolve' => static function ($value) {
50
+                        return $value['error'][1] ?? null;
51
+                    },
52
+                ];
53
+            } else {
54
+                throw new \Exception("If you specify errorCodes, you must also provide a validate callback");
55
+            }
56 56
         }
57 57
 
58 58
         $type = $config['type'];
Please login to merge, or discard this patch.
tests/Type/ErrorCodeTypeGenerationTest.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
     {
20 20
         $types = [];
21 21
         new UserErrorsType([
22
-        	'validate' => static function($val) {},
22
+            'validate' => static function($val) {},
23 23
             'errorCodes' => [
24 24
                 'unknownUser',
25 25
                 'userIsMinor',
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
                 'name' => 'bookInput',
80 80
                 'fields' => [
81 81
                     'authorId' => [
82
-	                    'validate' => static function($authorId) {},
82
+                        'validate' => static function($authorId) {},
83 83
                         'errorCodes' => ['unknownAuthor'],
84 84
                         'type' => Type::id(),
85 85
                         'description' => 'An author Id',
Please login to merge, or discard this patch.
tests/Type/UserErrorsType/InputObjectTest.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 
46 46
     public function testFieldsWithErrorCodesButNoValidate()
47 47
     {
48
-	    $this->expectExceptionMessage("If you specify errorCodes, you must also provide a validate callback");
48
+        $this->expectExceptionMessage("If you specify errorCodes, you must also provide a validate callback");
49 49
 
50
-	    $type  = new UserErrorsType([
50
+        $type  = new UserErrorsType([
51 51
             'type' => new InputObjectType([
52 52
                 'name' => 'bookInput',
53 53
                 'fields' => [
@@ -61,25 +61,25 @@  discard block
 block discarded – undo
61 61
         ], ['updateBook']);
62 62
     }
63 63
 
64
-	public function testFieldsWithValidate()
65
-	{
66
-		$type  = new UserErrorsType([
67
-			'type' => new InputObjectType([
68
-				'name' => 'bookInput',
69
-				'fields' => [
70
-					'authorId' => [
71
-						'errorCodes' => ['unknownAuthor'],
72
-						'validate' => static function(int $authorId) {
64
+    public function testFieldsWithValidate()
65
+    {
66
+        $type  = new UserErrorsType([
67
+            'type' => new InputObjectType([
68
+                'name' => 'bookInput',
69
+                'fields' => [
70
+                    'authorId' => [
71
+                        'errorCodes' => ['unknownAuthor'],
72
+                        'validate' => static function(int $authorId) {
73 73
 
74
-						},
75
-						'type' => Type::id(),
76
-						'description' => 'An author Id',
77
-					],
78
-				],
79
-			])
80
-		], ['updateBook']);
74
+                        },
75
+                        'type' => Type::id(),
76
+                        'description' => 'An author Id',
77
+                    ],
78
+                ],
79
+            ])
80
+        ], ['updateBook']);
81 81
 
82
-		self::assertEquals(Utils::nowdoc('
82
+        self::assertEquals(Utils::nowdoc('
83 83
 			schema {
84 84
 			  query: UpdateBookError
85 85
 			}
@@ -111,5 +111,5 @@  discard block
 block discarded – undo
111 111
 			}
112 112
 
113 113
 		'), SchemaPrinter::doPrint(new Schema(['query' => $type])));
114
-	}
114
+    }
115 115
 }
Please login to merge, or discard this patch.
tests/Type/ValidatedFieldDefinition/ListOfScalarValidationTest.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
             null,
94 94
             [
95 95
                 'phoneNumbers' => [
96
-                	[
97
-	                    '123-4567',
98
-	                    'xxx456-7890xxx'
99
-		            ]
96
+                    [
97
+                        '123-4567',
98
+                        'xxx456-7890xxx'
99
+                    ]
100 100
                 ],
101 101
             ]
102 102
         );
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
                         'phoneNumbers' =>
110 110
                             [
111 111
                                 'suberrors' =>
112
-	                                [
113
-	                                    'path' => [0,1],
114
-	                                    'code' => 'invalidPhoneNumber',
115
-	                                ]
112
+                                    [
113
+                                        'path' => [0,1],
114
+                                        'code' => 'invalidPhoneNumber',
115
+                                    ]
116 116
                             ],
117 117
                     ],
118 118
                 'result' => null,
@@ -152,39 +152,39 @@  discard block
 block discarded – undo
152 152
             null,
153 153
             [
154 154
                 'phoneNumbers' => [
155
-                	[],
156
-                	[
157
-	                    '123-4567',
158
-	                    'xxx-7890',
159
-	                    '321-1234'
160
-		            ]
155
+                    [],
156
+                    [
157
+                        '123-4567',
158
+                        'xxx-7890',
159
+                        '321-1234'
160
+                    ]
161 161
                 ],
162 162
             ]
163 163
         );
164 164
 
165 165
         static::assertEmpty($res->errors);
166 166
         static::assertEquals(
167
-	        array (
168
-		        'valid' => false,
169
-		        'suberrors' =>
170
-			        array (
171
-				        'phoneNumbers' =>
172
-					        array (
173
-						        'code' => NULL,
174
-						        'msg' => NULL,
175
-						        'suberrors' =>
176
-							        array (
177
-								        'path' =>
178
-									        array (
179
-										        0 => 1,
180
-										        1 => 1,
181
-									        ),
182
-								        'code' => 'invalidPhoneNumber',
183
-							        ),
184
-					        ),
185
-			        ),
186
-		        'result' => NULL,
187
-	        ),
167
+            array (
168
+                'valid' => false,
169
+                'suberrors' =>
170
+                    array (
171
+                        'phoneNumbers' =>
172
+                            array (
173
+                                'code' => NULL,
174
+                                'msg' => NULL,
175
+                                'suberrors' =>
176
+                                    array (
177
+                                        'path' =>
178
+                                            array (
179
+                                                0 => 1,
180
+                                                1 => 1,
181
+                                            ),
182
+                                        'code' => 'invalidPhoneNumber',
183
+                                    ),
184
+                            ),
185
+                    ),
186
+                'result' => NULL,
187
+            ),
188 188
             $res->data['setPhoneNumbers']
189 189
         );
190 190
 
Please login to merge, or discard this patch.
tests/Type/ValidatedFieldDefinition/ListOfInputObjectValidationTest.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
                             'args' => [
101 101
                                 'bookAttributes' => [
102 102
                                     'type' => Type::listOf($this->bookAttributesInputType),
103
-	                                'validate' => static function($var) {
104
-                        	            $i = 5;
105
-	                                },
106
-	                                'validateItem' => static function($book) {
107
-                        	            $res = isset($book['author']) || isset($book['title']) ? 0: 1;
108
-                        	            return $res;
109
-	                                }
103
+                                    'validate' => static function($var) {
104
+                                        $i = 5;
105
+                                    },
106
+                                    'validateItem' => static function($book) {
107
+                                        $res = isset($book['author']) || isset($book['title']) ? 0: 1;
108
+                                        return $res;
109
+                                    }
110 110
                                 ],
111 111
                             ],
112 112
                             'resolve' => static function ($value) : bool {
@@ -166,30 +166,30 @@  discard block
 block discarded – undo
166 166
             ]
167 167
         );
168 168
 
169
-	    static::assertEmpty($res->errors);
169
+        static::assertEmpty($res->errors);
170 170
 
171 171
         static::assertEquals(
172
-	        array (
173
-		        'valid' => false,
174
-		        'result' => NULL,
175
-		        'suberrors' =>
176
-			        array (
177
-				        'bookAttributes' =>
178
-					        array (
179
-						        'code' => NULL,
180
-						        'msg' => NULL,
181
-						        'suberrors' =>
182
-							        array (
183
-								        'code' => 1,
184
-								        'msg' => '',
185
-								        'path' =>
186
-									        array (
187
-										        0 => 1,
188
-									        ),
189
-							        ),
190
-					        ),
191
-			        ),
192
-	        ),
172
+            array (
173
+                'valid' => false,
174
+                'result' => NULL,
175
+                'suberrors' =>
176
+                    array (
177
+                        'bookAttributes' =>
178
+                            array (
179
+                                'code' => NULL,
180
+                                'msg' => NULL,
181
+                                'suberrors' =>
182
+                                    array (
183
+                                        'code' => 1,
184
+                                        'msg' => '',
185
+                                        'path' =>
186
+                                            array (
187
+                                                0 => 1,
188
+                                            ),
189
+                                    ),
190
+                            ),
191
+                    ),
192
+            ),
193 193
             $res->data['updateBooks']
194 194
         );
195 195
 
Please login to merge, or discard this patch.
src/Type/Definition/ValidateItemsError.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -2,11 +2,11 @@
 block discarded – undo
2 2
 namespace GraphQL\Type\Definition;
3 3
 
4 4
 class ValidateItemsError extends \Exception {
5
-	public $path;
6
-	public $error;
7
-	function __construct($path, $error) {
8
-		parent::__construct();
9
-		$this->path = $path;
10
-		$this->error = $error;
11
-	}
5
+    public $path;
6
+    public $error;
7
+    function __construct($path, $error) {
8
+        parent::__construct();
9
+        $this->path = $path;
10
+        $this->error = $error;
11
+    }
12 12
 }
13 13
\ No newline at end of file
Please login to merge, or discard this patch.
src/Type/Definition/ValidatedFieldDefinition.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -81,11 +81,11 @@
 block discarded – undo
81 81
         ]);
82 82
     }
83 83
 
84
-	protected function _isAssoc(array $arr)
85
-	{
86
-		if (array() === $arr) return false;
87
-		return array_keys($arr) !== range(0, count($arr) - 1);
88
-	}
84
+    protected function _isAssoc(array $arr)
85
+    {
86
+        if (array() === $arr) return false;
87
+        return array_keys($arr) !== range(0, count($arr) - 1);
88
+    }
89 89
 
90 90
     protected function _validateItems($value, array $path, callable $validate) {
91 91
         foreach ($value as $idx => $subValue) {
Please login to merge, or discard this patch.
tests/Type/UserErrorsType/ListOfTest.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -118,21 +118,21 @@  discard block
 block discarded – undo
118 118
     public function testListOfInputObjectWithValidationOnSelf()
119 119
     {
120 120
         $type  = new UserErrorsType([
121
-	        'validate' => static function(array $authors) {
122
-        	    if(count($authors) < 1) {
123
-        	    	return ['atLeastOneAuthorRequired', "You must submit at least one author"];
124
-	            }
125
-	        },
126
-	        'errorCodes' => ['atLeastOneBookRequired'],
127
-	        'type' => Type::listOf(new InputObjectType([
121
+            'validate' => static function(array $authors) {
122
+                if(count($authors) < 1) {
123
+                    return ['atLeastOneAuthorRequired', "You must submit at least one author"];
124
+                }
125
+            },
126
+            'errorCodes' => ['atLeastOneBookRequired'],
127
+            'type' => Type::listOf(new InputObjectType([
128 128
                 'name'=> 'Author',
129 129
                 'fields' => [
130 130
                     'firstName' => [
131 131
                         'type' => Type::string(),
132 132
                     ],
133
-	                'lastName' => [
134
-		                'type' => Type::string(),
135
-	                ],
133
+                    'lastName' => [
134
+                        'type' => Type::string(),
135
+                    ],
136 136
                 ],
137 137
             ]))
138 138
         ], ['authorList']);
@@ -159,30 +159,30 @@  discard block
 block discarded – undo
159 159
 		'), SchemaPrinter::doPrint(new Schema(['query' => $type])));
160 160
     }
161 161
 
162
-	public function testListOfInputObjectWithValidationOnWrappedSelf()
163
-	{
164
-		$type  = new UserErrorsType([
165
-			'suberrorCodes' => ['firstNameOrLastNameRequired'],
166
-			'validateItem' => static function(array $author) {
167
-				if(!isset($author['firstName']) && !isset($author['lastName'])) {
168
-					return ['atLeastOneAuthorRequired', "You must submit a first name or a last name"];
169
-				}
170
-			},
171
-			'type' => Type::listOf(new InputObjectType([
172
-				'name'=> 'Author',
173
-				'fields' => [
174
-					'firstName' => [
175
-						'type' => Type::string(),
176
-						'validate' => function(string $name) {}
177
-					],
178
-					'lastName' => [
179
-						'type' => Type::string(),
180
-					],
181
-				],
182
-			]))
183
-		], ['authorList']);
184
-
185
-		self::assertEquals(Utils::nowdoc('
162
+    public function testListOfInputObjectWithValidationOnWrappedSelf()
163
+    {
164
+        $type  = new UserErrorsType([
165
+            'suberrorCodes' => ['firstNameOrLastNameRequired'],
166
+            'validateItem' => static function(array $author) {
167
+                if(!isset($author['firstName']) && !isset($author['lastName'])) {
168
+                    return ['atLeastOneAuthorRequired', "You must submit a first name or a last name"];
169
+                }
170
+            },
171
+            'type' => Type::listOf(new InputObjectType([
172
+                'name'=> 'Author',
173
+                'fields' => [
174
+                    'firstName' => [
175
+                        'type' => Type::string(),
176
+                        'validate' => function(string $name) {}
177
+                    ],
178
+                    'lastName' => [
179
+                        'type' => Type::string(),
180
+                    ],
181
+                ],
182
+            ]))
183
+        ], ['authorList']);
184
+
185
+        self::assertEquals(Utils::nowdoc('
186 186
 			schema {
187 187
 			  query: AuthorListError
188 188
 			}
@@ -229,5 +229,5 @@  discard block
 block discarded – undo
229 229
 			}
230 230
 
231 231
 		'), SchemaPrinter::doPrint(new Schema(['query' => $type])));
232
-	}
232
+    }
233 233
 }
Please login to merge, or discard this patch.