Failed Conditions
Pull Request — master (#1)
by Max
04:08
created
tests/Utils.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
 class Utils
15 15
 {
16
-    public static function nowdoc(string $str) : string
16
+    public static function nowdoc (string $str) : string
17 17
     {
18 18
         $lines = preg_split('/\\n/', $str);
19 19
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         }
27 27
 
28 28
         // Toss out the first and last lines.
29
-        $lines = array_slice($lines, 1, count($lines) - 2);
29
+        $lines = array_slice($lines, 1, count($lines)-2);
30 30
 
31 31
         // take the tabs from the first line, and subtract them from all lines
32 32
         $matches = [];
Please login to merge, or discard this patch.
src/Type/Definition/ValidatedFieldDefinition.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -183,7 +183,7 @@
 block discarded – undo
183 183
     }
184 184
 
185 185
     /**
186
-     * @return mixed|string|string[]|null
186
+     * @return string
187 187
      *
188 188
      * @throws ReflectionException
189 189
      */
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     /**
25 25
      * @param mixed[] $config
26 26
      */
27
-    public function __construct(array $config)
27
+    public function __construct (array $config)
28 28
     {
29 29
         $args = $config['args'];
30 30
         $name = $config['name'] ?? lcfirst($this->tryInferName());
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
@@ -83,12 +83,12 @@  discard block
 block discarded – undo
83 83
     /**
84 84
      * @param   mixed[] $arr
85 85
      */
86
-    protected function _isAssoc(array $arr) : bool
86
+    protected function _isAssoc (array $arr) : bool
87 87
     {
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
     /**
@@ -97,16 +97,16 @@  discard block
 block discarded – undo
97 97
      *
98 98
      * @throws  ValidateItemsError
99 99
      */
100
-    protected function _validateItems(array $value, array $path, callable $validate) : void
100
+    protected function _validateItems (array $value, array $path, callable $validate) : void
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) {
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      * @param mixed $value
122 122
      * @return mixed[]
123 123
      */
124
-    protected function _validate(array $arg, $value) : array
124
+    protected function _validate (array $arg, $value) : array
125 125
     {
126 126
         $res = [];
127 127
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      *
190 190
      * @throws ReflectionException
191 191
      */
192
-    protected function tryInferName()
192
+    protected function tryInferName ()
193 193
     {
194 194
         // If class is extended - infer name from className
195 195
         // QueryType -> Type
Please login to merge, or discard this patch.
tests/Type/ValidatedFieldDefinition/InputObjectValidationTest.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,6 @@
 block discarded – undo
9 9
 use GraphQL\Type\Definition\InputObjectType;
10 10
 use GraphQL\Type\Definition\ObjectType;
11 11
 use GraphQL\Type\Definition\Type;
12
-use GraphQL\Type\Definition\UserErrorsType;
13 12
 use GraphQL\Type\Definition\ValidatedFieldDefinition;
14 13
 use GraphQL\Type\Schema;
15 14
 use PHPUnit\Framework\TestCase;
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     /** @var Schema */
42 42
     protected $schema;
43 43
 
44
-    protected function setUp(): void
44
+    protected function setUp (): void
45 45
     {
46 46
         $this->personType = new ObjectType([
47 47
             'name' => 'Person',
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 (empty($bookAttributes)) {
105 105
                                             return 0;
106 106
                                         }
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
                                     },
113 113
                                 ],
114 114
                             ],
115
-                            'resolve' => static function ($value) : bool {
115
+                            'resolve' => static function($value) : bool {
116 116
                                 // ...
117 117
                                 // do update
118 118
                                 // ...
119 119
 
120
-                                return ! $value;
120
+                                return !$value;
121 121
                             },
122 122
                         ]),
123 123
                     ];
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         ]);
127 127
     }
128 128
 
129
-    public function testValidationInputObjectFieldFail(): void
129
+    public function testValidationInputObjectFieldFail (): void
130 130
     {
131 131
         $res = GraphQL::executeQuery(
132 132
             $this->schema,
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
         static::assertFalse($res->data['updateBook']['valid']);
197 197
     }
198 198
 
199
-    public function testValidationInputObjectSelfFail(): void
199
+    public function testValidationInputObjectSelfFail (): void
200 200
     {
201 201
         $res = GraphQL::executeQuery(
202 202
             $this->schema,
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
         static::assertFalse($res->data['updateBook']['valid']);
259 259
     }
260 260
 
261
-    public function testValidationSuccess(): void
261
+    public function testValidationSuccess (): void
262 262
     {
263 263
         $res = GraphQL::executeQuery(
264 264
             $this->schema,
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
         static::assertTrue($res->data['updateBook']['valid']);
312 312
     }
313 313
 
314
-    public function testValidationEmptyInput(): void
314
+    public function testValidationEmptyInput (): void
315 315
     {
316 316
         $res = GraphQL::executeQuery(
317 317
             $this->schema,
Please login to merge, or discard this patch.
tests/Type/ErrorCodeTypeGenerationTest.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -15,18 +15,18 @@  discard block
 block discarded – undo
15 15
 
16 16
 final class ErrorCodeTypeGenerationTest extends TestCase
17 17
 {
18
-    public function testMultipleErrorCodesOnSelf(): void
18
+    public function testMultipleErrorCodesOnSelf (): void
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): void {
29
+            'typeSetter' => static function($type) use (&$types): void {
30 30
                 $types[$type->name] = $type;
31 31
             },
32 32
             'type' => new IDType(['name' => 'User']),
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
         );
47 47
     }
48 48
 
49
-    public function testFieldsWithNoErrorCodes(): void
49
+    public function testFieldsWithNoErrorCodes (): void
50 50
     {
51 51
         $types = [];
52 52
         $type  = new UserErrorsType([
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
                     ],
60 60
                 ],
61 61
             ]),
62
-            'typeSetter' => static function ($type) use (&$types): void {
62
+            'typeSetter' => static function($type) use (&$types): void {
63 63
                 $types[$type->name] = $type;
64 64
             },
65 65
         ], ['updateBook']);
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         '));
74 74
     }
75 75
 
76
-    public function testFieldsWithErrorCodes(): void
76
+    public function testFieldsWithErrorCodes (): void
77 77
     {
78 78
         $types = [];
79 79
         new UserErrorsType([
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
90 90
                     ],
91 91
                 ],
92 92
             ]),
93
-            'typeSetter' => static function ($type) use (&$types): void {
93
+            'typeSetter' => static function($type) use (&$types): void {
94 94
                 $types[$type->name] = $type;
95 95
             },
96 96
         ], ['updateBook']);
Please login to merge, or discard this patch.
tests/Type/UserErrorsType/ListOfTest.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 final class ListOfTest extends TestCase
17 17
 {
18
-    public function testScalarTypeWithNoValidation(): void
18
+    public function testScalarTypeWithNoValidation (): void
19 19
     {
20 20
         $type = new UserErrorsType([
21 21
             'type' => Type::listOf(Type::id()),
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
         '), SchemaPrinter::doPrint(new Schema(['query' => $type])));
35 35
     }
36 36
 
37
-    public function testListOfScalarWithValidationOnSelf(): void
37
+    public function testListOfScalarWithValidationOnSelf (): void
38 38
     {
39 39
         $type = new UserErrorsType([
40 40
             'type' => Type::listOf(Type::id()),
41 41
             'errorCodes'=> ['atLeastOneRequired'],
42
-            'validate' => static function ($value) {
42
+            'validate' => static function($value) {
43 43
                 return $value ? 0 : 1;
44 44
             },
45 45
         ], ['users']);
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
         '), SchemaPrinter::doPrint(new Schema(['query' => $type])));
67 67
     }
68 68
 
69
-    public function testListOfListOfListOfScalarWithValidationOnSelfAndWrappedType(): void
69
+    public function testListOfListOfListOfScalarWithValidationOnSelfAndWrappedType (): void
70 70
     {
71 71
         $type = new UserErrorsType([
72 72
             'type' => Type::listOf(Type::listOf(Type::listOf(Type::id()))),
73 73
             'errorCodes'=> ['atLeastOneRequired'],
74
-            'validate' => static function ($value) {
74
+            'validate' => static function($value) {
75 75
                 return $value ? 0 : 1;
76 76
             },
77
-            'validateItem' => static function ($value) {
77
+            'validateItem' => static function($value) {
78 78
                 return $value ? 0 : 1;
79 79
             },
80 80
         ], ['users']);
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
         '), SchemaPrinter::doPrint(new Schema(['query' => $type])));
117 117
     }
118 118
 
119
-    public function testListOfInputObjectWithValidationOnSelf(): void
119
+    public function testListOfInputObjectWithValidationOnSelf (): void
120 120
     {
121 121
         $type = new UserErrorsType([
122
-            'validate' => static function (array $authors) {
122
+            'validate' => static function(array $authors) {
123 123
                 if (count($authors) < 1) {
124 124
                     return ['atLeastOneAuthorRequired', 'You must submit at least one author'];
125 125
                 }
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
         '), SchemaPrinter::doPrint(new Schema(['query' => $type])));
161 161
     }
162 162
 
163
-    public function testListOfInputObjectWithValidationOnWrappedSelf(): void
163
+    public function testListOfInputObjectWithValidationOnWrappedSelf (): void
164 164
     {
165 165
         $type = new UserErrorsType([
166 166
             'suberrorCodes' => ['firstNameOrLastNameRequired'],
167
-            'validateItem' => static function (array $author) {
168
-                if (! isset($author['firstName']) && ! isset($author['lastName'])) {
167
+            'validateItem' => static function(array $author) {
168
+                if (!isset($author['firstName']) && !isset($author['lastName'])) {
169 169
                     return ['atLeastOneAuthorRequired', 'You must submit a first name or a last name'];
170 170
                 }
171 171
             },
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
                 'fields' => [
175 175
                     'firstName' => [
176 176
                         'type' => Type::string(),
177
-                        'validate' => static function (string $name) {
177
+                        'validate' => static function(string $name) {
178 178
                             return $name ? 0 : 1;
179 179
                         },
180 180
                     ],
Please login to merge, or discard this patch.
tests/Type/UserErrorsType/ScalarTest.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 final class ScalarTest extends TestCase
16 16
 {
17
-    public function testNoValidation(): void
17
+    public function testNoValidation (): void
18 18
     {
19 19
         $type = new UserErrorsType([
20 20
             'type' => Type::id(),
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
         '), SchemaPrinter::doPrint(new Schema(['query' => $type])));
34 34
     }
35 35
 
36
-    public function testWithValidation(): void
36
+    public function testWithValidation (): void
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']),
Please login to merge, or discard this patch.
tests/Type/UserErrorsType/BasicTest.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
 final class BasicTest extends TestCase
15 15
 {
16
-    public function testNoValidationOnSelf(): void
16
+    public function testNoValidationOnSelf (): void
17 17
     {
18 18
         $type = new UserErrorsType([
19 19
             'type' => Type::id(),
@@ -32,20 +32,20 @@  discard block
 block discarded – undo
32 32
         '), SchemaPrinter::doPrint(new Schema(['query' => $type])));
33 33
     }
34 34
 
35
-    public function testNoType(): void
35
+    public function testNoType (): void
36 36
     {
37 37
         $this->expectExceptionMessage('You must specify a type for your field');
38 38
         UserErrorsType::create([
39
-            'validate' => static function ($value) {
39
+            'validate' => static function($value) {
40 40
                 return $value ? 0 : 1;
41 41
             },
42 42
         ], ['upsertSku']);
43 43
     }
44 44
 
45
-    public function testValidationWithNoErrorCodes(): void
45
+    public function testValidationWithNoErrorCodes (): void
46 46
     {
47 47
         $type = UserErrorsType::create([
48
-            'validate' => static function ($value) {
48
+            'validate' => static function($value) {
49 49
                 return $value ? 0 : 1;
50 50
             },
51 51
             'type' => Type::id(),
Please login to merge, or discard this patch.
tests/Type/UserErrorsType/InputObjectTest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 final class InputObjectTest extends TestCase
17 17
 {
18
-    public function testFieldsWithNoErrorCodes(): void
18
+    public function testFieldsWithNoErrorCodes (): void
19 19
     {
20 20
         $type = new UserErrorsType([
21 21
             'type' => new InputObjectType([
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
         );
46 46
     }
47 47
 
48
-    public function testFieldsWithErrorCodesButNoValidate(): void
48
+    public function testFieldsWithErrorCodesButNoValidate (): void
49 49
     {
50 50
         $this->expectExceptionMessage('If you specify errorCodes, you must also provide a validate callback');
51 51
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         ], ['updateBook']);
64 64
     }
65 65
 
66
-    public function testFieldsWithValidate(): void
66
+    public function testFieldsWithValidate (): void
67 67
     {
68 68
         $type = new UserErrorsType([
69 69
             'type' => new InputObjectType([
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
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(),
Please login to merge, or discard this patch.
tests/Type/ValidatedFieldDefinition/NonNullScalarValidationTest.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     /** @var Schema */
37 37
     protected $schema;
38 38
 
39
-    protected function setUp(): void
39
+    protected function setUp (): void
40 40
     {
41 41
         $this->personType = new ObjectType([
42 42
             'name' => 'Person',
@@ -55,13 +55,13 @@  discard block
 block discarded – undo
55 55
             'fields' => [
56 56
                 'title' => [
57 57
                     'type' => Type::string(),
58
-                    'resolve' => static function ($book) {
58
+                    'resolve' => static function($book) {
59 59
                         return $book['title'];
60 60
                     },
61 61
                 ],
62 62
                 'author' => [
63 63
                     'type' => $this->personType,
64
-                    'resolve' => static function ($book) {
64
+                    'resolve' => static function($book) {
65 65
                         return $book['author'];
66 66
                     },
67 67
                 ],
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         $this->schema = new Schema([
72 72
             'mutation' => new ObjectType([
73 73
                 'name' => 'Mutation',
74
-                'fields' => function () {
74
+                'fields' => function() {
75 75
                     return [
76 76
                         'updateBook' => new ValidatedFieldDefinition([
77 77
                             'name' => 'updateBook',
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
                                 'bookId' => [
81 81
                                     'type' => Type::nonNull(Type::id()),
82 82
                                     'errorCodes' => ['bookNotFound'],
83
-                                    'validate' => function ($bookId) {
83
+                                    'validate' => function($bookId) {
84 84
                                         if (isset($this->data['books'][$bookId])) {
85 85
                                             return 0;
86 86
                                         }
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
                                     },
90 90
                                 ],
91 91
                             ],
92
-                            'resolve' => function ($value, $args) : array {
92
+                            'resolve' => function($value, $args) : array {
93 93
                                 return $this->data['books'][$args['bookId']];
94 94
                             },
95 95
                         ]),
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         ]);
100 100
     }
101 101
 
102
-    public function testNonNullScalarValidationSuccess(): void
102
+    public function testNonNullScalarValidationSuccess (): void
103 103
     {
104 104
         $res = GraphQL::executeQuery(
105 105
             $this->schema,
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
         static::assertTrue($res->data['updateBook']['valid']);
130 130
     }
131 131
 
132
-    public function testNonNullScalarValidationFail() : void
132
+    public function testNonNullScalarValidationFail () : void
133 133
     {
134 134
         $res = GraphQL::executeQuery(
135 135
             $this->schema,
Please login to merge, or discard this patch.