21
21
use function preg_replace ;
22
22
23
23
/**
24
- * Registry of standard GraphQL types
25
- * and a base class for all other types.
24
+ * Registry of standard GraphQL types and base class for all other types.
26
25
*/
27
26
abstract class Type implements JsonSerializable
28
27
{
@@ -35,7 +34,7 @@ abstract class Type implements JsonSerializable
35
34
/** @var array<string, ScalarType> */
36
35
protected static $ standardTypes ;
37
36
38
- /** @var Type[] */
37
+ /** @var array<string, Type> */
39
38
private static $ builtInTypes ;
40
39
41
40
/** @var string */
@@ -47,10 +46,10 @@ abstract class Type implements JsonSerializable
47
46
/** @var (Node&TypeDefinitionNode)|null */
48
47
public $ astNode ;
49
48
50
- /** @var mixed[] */
49
+ /** @var array<string, mixed> */
51
50
public $ config ;
52
51
53
- /** @var TypeExtensionNode[] */
52
+ /** @var array<Node& TypeExtensionNode> */
54
53
public $ extensionASTNodes ;
55
54
56
55
/**
@@ -114,38 +113,45 @@ public static function float(): ScalarType
114
113
}
115
114
116
115
/**
116
+ * @param Type|callable():Type $type
117
+ *
117
118
* @api
118
119
*/
119
- public static function listOf (Type $ wrappedType ): ListOfType
120
+ public static function listOf ($ type ): ListOfType
120
121
{
121
- return new ListOfType ($ wrappedType );
122
+ return new ListOfType ($ type );
122
123
}
123
124
124
125
/**
125
- * @param callable|NullableType $wrappedType
126
+ * code sniffer doesn't understand this syntax. Pr with a fix here: waiting on https://github.com/squizlabs/PHP_CodeSniffer/pull/2919
127
+ * phpcs:disable Squiz.Commenting.FunctionComment.SpacingAfterParamType
128
+ * @param (NullableType&Type)|callable():(NullableType&Type) $type
126
129
*
127
130
* @api
128
131
*/
129
- public static function nonNull ($ wrappedType ): NonNull
132
+ public static function nonNull ($ type ): NonNull
130
133
{
131
- return new NonNull ($ wrappedType );
134
+ return new NonNull ($ type );
132
135
}
133
136
134
137
/**
135
- * Checks if the type is a builtin type
138
+ * Checks if the type is a builtin type.
136
139
*/
137
140
public static function isBuiltInType (Type $ type ): bool
138
141
{
139
- return in_array ($ type ->name , array_keys (self ::getAllBuiltInTypes ()), true );
142
+ return in_array (
143
+ $ type ->name ,
144
+ array_keys (self ::getAllBuiltInTypes ()),
145
+ true
146
+ );
140
147
}
141
148
142
149
/**
143
- * Returns all builtin in types including base scalar and
144
- * introspection types
150
+ * Returns all builtin in types including base scalar and introspection types.
145
151
*
146
- * @return Type[]
152
+ * @return array<string, Type>
147
153
*/
148
- public static function getAllBuiltInTypes ()
154
+ public static function getAllBuiltInTypes (): array
149
155
{
150
156
if (self ::$ builtInTypes === null ) {
151
157
self ::$ builtInTypes = array_merge (
@@ -158,11 +164,11 @@ public static function getAllBuiltInTypes()
158
164
}
159
165
160
166
/**
161
- * Returns all builtin scalar types
167
+ * Returns all builtin scalar types.
162
168
*
163
- * @return ScalarType[]
169
+ * @return array<string, ScalarType>
164
170
*/
165
- public static function getStandardTypes ()
171
+ public static function getStandardTypes (): array
166
172
{
167
173
return [
168
174
self ::ID => static ::id (),
@@ -176,7 +182,7 @@ public static function getStandardTypes()
176
182
/**
177
183
* @param array<string, ScalarType> $types
178
184
*/
179
- public static function overrideStandardTypes (array $ types )
185
+ public static function overrideStandardTypes (array $ types ): void
180
186
{
181
187
$ standardTypes = self ::getStandardTypes ();
182
188
foreach ($ types as $ type ) {
@@ -197,8 +203,6 @@ public static function overrideStandardTypes(array $types)
197
203
}
198
204
199
205
/**
200
- * @param Type $type
201
- *
202
206
* @api
203
207
*/
204
208
public static function isInputType ($ type ): bool
@@ -207,16 +211,10 @@ public static function isInputType($type): bool
207
211
}
208
212
209
213
/**
210
- * @param Type $type
211
- *
212
214
* @api
213
215
*/
214
216
public static function getNamedType ($ type ): ?Type
215
217
{
216
- if ($ type === null ) {
217
- return null ;
218
- }
219
-
220
218
while ($ type instanceof WrappingType) {
221
219
$ type = $ type ->getWrappedType ();
222
220
}
@@ -225,8 +223,6 @@ public static function getNamedType($type): ?Type
225
223
}
226
224
227
225
/**
228
- * @param Type $type
229
- *
230
226
* @api
231
227
*/
232
228
public static function isOutputType ($ type ): bool
@@ -235,8 +231,6 @@ public static function isOutputType($type): bool
235
231
}
236
232
237
233
/**
238
- * @param Type $type
239
- *
240
234
* @api
241
235
*/
242
236
public static function isLeafType ($ type ): bool
@@ -245,8 +239,6 @@ public static function isLeafType($type): bool
245
239
}
246
240
247
241
/**
248
- * @param Type $type
249
- *
250
242
* @api
251
243
*/
252
244
public static function isCompositeType ($ type ): bool
@@ -255,21 +247,19 @@ public static function isCompositeType($type): bool
255
247
}
256
248
257
249
/**
258
- * @param Type $type
259
- *
260
250
* @api
261
251
*/
262
252
public static function isAbstractType ($ type ): bool
263
253
{
264
254
return $ type instanceof AbstractType;
265
255
}
266
256
267
- /**
268
- * @param mixed $type
269
- */
270
257
public static function assertType ($ type ): Type
271
258
{
272
- assert ($ type instanceof Type, new InvariantViolation ('Expected ' . Utils::printSafe ($ type ) . ' to be a GraphQL type. ' ));
259
+ assert (
260
+ $ type instanceof Type,
261
+ new InvariantViolation ('Expected ' . Utils::printSafe ($ type ) . ' to be a GraphQL type. ' )
262
+ );
273
263
274
264
return $ type ;
275
265
}
@@ -287,39 +277,27 @@ public static function getNullableType(Type $type): Type
287
277
/**
288
278
* @throws InvariantViolation
289
279
*/
290
- public function assertValid ()
280
+ public function assertValid (): void
291
281
{
292
282
Utils::assertValidName ($ this ->name );
293
283
}
294
284
295
- /**
296
- * @return string
297
- */
298
- public function jsonSerialize ()
285
+ public function jsonSerialize (): string
299
286
{
300
287
return $ this ->toString ();
301
288
}
302
289
303
- /**
304
- * @return string
305
- */
306
- public function toString ()
290
+ public function toString (): string
307
291
{
308
292
return $ this ->name ;
309
293
}
310
294
311
- /**
312
- * @return string
313
- */
314
- public function __toString ()
295
+ public function __toString (): string
315
296
{
316
297
return $ this ->toString ();
317
298
}
318
299
319
- /**
320
- * @return string|null
321
- */
322
- protected function tryInferName ()
300
+ protected function tryInferName (): ?string
323
301
{
324
302
if ($ this ->name ) {
325
303
return $ this ->name ;
0 commit comments