Failed Conditions
Pull Request — master (#1)
by Max
04:08
created
tests/Type/ValidatedFieldDefinition/ListOfScalarValidationTest.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
     /** @var Schema */
25 25
     protected $schema;
26 26
 
27
-    protected function setUp(): void
27
+    protected function setUp (): void
28 28
     {
29 29
         $this->query  = new ObjectType(['name' => 'Query']);
30 30
         $this->schema = new Schema([
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,21 +40,21 @@  discard block
 block discarded – undo
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) : bool {
57
-                                return ! empty($phoneNumbers);
56
+                            'resolve' => static function(array $phoneNumbers) : bool {
57
+                                return !empty($phoneNumbers);
58 58
                             },
59 59
                         ]),
60 60
                     ];
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         ]);
64 64
     }
65 65
 
66
-    public function testItemsValidationOnWrappedTypeFail(): void
66
+    public function testItemsValidationOnWrappedTypeFail (): void
67 67
     {
68 68
         $res = GraphQL::executeQuery(
69 69
             $this->schema,
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
                             [
107 107
                                 'suberrors' =>
108 108
                                     [
109
-                                        'path' => [0,1],
109
+                                        'path' => [0, 1],
110 110
                                         'code' => 'invalidPhoneNumber',
111 111
                                     ],
112 112
                             ],
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         static::assertFalse($res->data['setPhoneNumbers']['valid']);
121 121
     }
122 122
 
123
-    public function testItemsValidationOnSelfFail(): void
123
+    public function testItemsValidationOnSelfFail (): void
124 124
     {
125 125
         $res = GraphQL::executeQuery(
126 126
             $this->schema,
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
         static::assertFalse($res->data['setPhoneNumbers']['valid']);
173 173
     }
174 174
 
175
-    public function testListOfValidationFail(): void
175
+    public function testListOfValidationFail (): void
176 176
     {
177 177
         $res = GraphQL::executeQuery(
178 178
             $this->schema,
Please login to merge, or discard this patch.
tests/Type/ValidatedFieldDefinition/ScalarValidationTest.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
     /** @var Schema */
40 40
     protected $schema;
41 41
 
42
-    protected function setUp() : void
42
+    protected function setUp () : void
43 43
     {
44 44
         $this->personType = new ObjectType([
45 45
             '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
                 ],
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
             'query' => $this->query,
75 75
             'mutation' => new ObjectType([
76 76
                 'name' => 'Mutation',
77
-                'fields' => function () {
77
+                'fields' => function() {
78 78
                     return [
79 79
                         'updateBook' => new ValidatedFieldDefinition([
80 80
                             'name' => 'updateBook',
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
                                 'bookId' => [
84 84
                                     'type' => Type::id(),
85 85
                                     'errorCodes' => ['bookNotFound'],
86
-                                    'validate' => function ($bookId) {
86
+                                    'validate' => function($bookId) {
87 87
                                         if (isset($this->data['books'][$bookId])) {
88 88
                                             return 0;
89 89
                                         }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
                                     },
93 93
                                 ],
94 94
                             ],
95
-                            'resolve' => static function ($value) : bool {
95
+                            'resolve' => static function($value) : bool {
96 96
                                 return !!$value;
97 97
                             },
98 98
                         ]),
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
         ]);
103 103
     }
104 104
 
105
-    public function testNullableScalarValidationOnNullValueSuccess() : void
105
+    public function testNullableScalarValidationOnNullValueSuccess () : void
106 106
     {
107 107
         $res = GraphQL::executeQuery(
108 108
             $this->schema,
Please login to merge, or discard this patch.
tests/Type/ValidatedFieldDefinition/ListOfInputObjectValidationTest.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     /** @var Schema */
43 43
     protected $schema;
44 44
 
45
-    protected function setUp(): void
45
+    protected function setUp (): void
46 46
     {
47 47
         $this->personType = new ObjectType([
48 48
             'name' => 'Person',
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,15 +100,15 @@  discard block
 block discarded – undo
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 {
111
+                            'resolve' => static function($value) : bool {
112 112
                                 return !!$value;
113 113
                             },
114 114
                         ]),
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
         ]);
119 119
     }
120 120
 
121
-    public function testValidationFail(): void
121
+    public function testValidationFail (): void
122 122
     {
123 123
         $res = GraphQL::executeQuery(
124 124
             $this->schema,
Please login to merge, or discard this patch.
src/Type/Definition/ValidateItemsError.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
      * @param int[] $path
20 20
      * @param mixed $error
21 21
      */
22
-    public function __construct(array $path, $error)
22
+    public function __construct (array $path, $error)
23 23
     {
24 24
         parent::__construct();
25 25
         $this->path  = $path;
Please login to merge, or discard this patch.
src/Type/Definition/UserErrorsType.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,18 +20,18 @@  discard block
 block discarded – undo
20 20
      * @param mixed[]  $config
21 21
      * @param string[] $path
22 22
      */
23
-    public function __construct(array $config, array $path, bool $isParentList = false)
23
+    public function __construct (array $config, array $path, bool $isParentList = false)
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
             ];
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      *
150 150
      * @return mixed
151 151
      */
152
-    protected function _set(Type $type, array $config)
152
+    protected function _set (Type $type, array $config)
153 153
     {
154 154
         if (is_callable($config['typeSetter'] ?? null)) {
155 155
             $config['typeSetter']($type);
@@ -166,14 +166,14 @@  discard block
 block discarded – undo
166 166
      *
167 167
      * @throws Exception
168 168
      */
169
-    public static function create(array $config, array $path, bool $isParentList = false, string $name = '') : ?self
169
+    public static function create (array $config, array $path, bool $isParentList = false, string $name = '') : ?self
170 170
     {
171 171
         $config['fields'] = $config['fields'] ?? [];
172 172
         if (isset($config['validate']) && is_callable($config['validate'])) {
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
 block discarded – undo
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':
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
     /**
212 212
      * @param string[] $path
213 213
      */
214
-    protected function _nameFromPath(array $path) : string
214
+    protected function _nameFromPath (array $path) : string
215 215
     {
216 216
         return implode('_', array_map('ucfirst', $path));
217 217
     }
Please login to merge, or discard this patch.