Skip to content

Commit 4658b60

Browse files
authored
Avoid unnecessary @throws annotations for known correct configuration (#1716)
1 parent 66b0dda commit 4658b60

File tree

4 files changed

+73
-63
lines changed

4 files changed

+73
-63
lines changed

docs/class-reference.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,51 +184,53 @@ Registry of standard GraphQL types and base class for all other types.
184184

185185
```php
186186
/**
187-
* @api
187+
* Returns the registered or default standard Int type.
188188
*
189-
* @throws InvariantViolation
189+
* @api
190190
*/
191191
static function int(): GraphQL\Type\Definition\ScalarType
192192
```
193193

194194
```php
195195
/**
196-
* @api
196+
* Returns the registered or default standard Float type.
197197
*
198-
* @throws InvariantViolation
198+
* @api
199199
*/
200200
static function float(): GraphQL\Type\Definition\ScalarType
201201
```
202202

203203
```php
204204
/**
205-
* @api
205+
* Returns the registered or default standard String type.
206206
*
207-
* @throws InvariantViolation
207+
* @api
208208
*/
209209
static function string(): GraphQL\Type\Definition\ScalarType
210210
```
211211

212212
```php
213213
/**
214-
* @api
214+
* Returns the registered or default standard Boolean type.
215215
*
216-
* @throws InvariantViolation
216+
* @api
217217
*/
218218
static function boolean(): GraphQL\Type\Definition\ScalarType
219219
```
220220

221221
```php
222222
/**
223-
* @api
223+
* Returns the registered or default standard ID type.
224224
*
225-
* @throws InvariantViolation
225+
* @api
226226
*/
227227
static function id(): GraphQL\Type\Definition\ScalarType
228228
```
229229

230230
```php
231231
/**
232+
* Wraps the given type in a list type.
233+
*
232234
* @template T of Type
233235
*
234236
* @param T|callable():T $type
@@ -242,6 +244,8 @@ static function listOf($type): GraphQL\Type\Definition\ListOfType
242244

243245
```php
244246
/**
247+
* Wraps the given type in a non-null type.
248+
*
245249
* @param (NullableType&Type)|callable():(NullableType&Type) $type
246250
*
247251
* @api
@@ -251,6 +255,8 @@ static function nonNull($type): GraphQL\Type\Definition\NonNull
251255

252256
```php
253257
/**
258+
* Determines if the given type is an input type.
259+
*
254260
* @param mixed $type
255261
*
256262
* @api
@@ -260,6 +266,8 @@ static function isInputType($type): bool
260266

261267
```php
262268
/**
269+
* Returns the underlying named type of the given type.
270+
*
263271
* @return (Type&NamedType)|null
264272
*
265273
* @api
@@ -269,6 +277,8 @@ static function getNamedType(?GraphQL\Type\Definition\Type $type): ?GraphQL\Type
269277

270278
```php
271279
/**
280+
* Determines if the given type is an output type.
281+
*
272282
* @param mixed $type
273283
*
274284
* @api
@@ -278,6 +288,8 @@ static function isOutputType($type): bool
278288

279289
```php
280290
/**
291+
* Determines if the given type is a leaf type.
292+
*
281293
* @param mixed $type
282294
*
283295
* @api
@@ -287,6 +299,8 @@ static function isLeafType($type): bool
287299

288300
```php
289301
/**
302+
* Determines if the given type is a composite type.
303+
*
290304
* @param mixed $type
291305
*
292306
* @api
@@ -296,6 +310,8 @@ static function isCompositeType($type): bool
296310

297311
```php
298312
/**
313+
* Determines if the given type is an abstract type.
314+
*
299315
* @param mixed $type
300316
*
301317
* @api
@@ -305,6 +321,8 @@ static function isAbstractType($type): bool
305321

306322
```php
307323
/**
324+
* Unwraps a potentially non-null type to return the underlying nullable type.
325+
*
308326
* @return Type&NullableType
309327
*
310328
* @api

src/Type/Definition/Directive.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace GraphQL\Type\Definition;
44

5-
use GraphQL\Error\InvariantViolation;
65
use GraphQL\Language\AST\DirectiveDefinitionNode;
76
use GraphQL\Language\DirectiveLocation;
87

@@ -75,11 +74,7 @@ public function __construct(array $config)
7574
$this->config = $config;
7675
}
7776

78-
/**
79-
* @throws InvariantViolation
80-
*
81-
* @return array<string, Directive>
82-
*/
77+
/** @return array<string, Directive> */
8378
public static function getInternalDirectives(): array
8479
{
8580
return [
@@ -89,7 +84,6 @@ public static function getInternalDirectives(): array
8984
];
9085
}
9186

92-
/** @throws InvariantViolation */
9387
public static function includeDirective(): Directive
9488
{
9589
return self::$internalDirectives[self::INCLUDE_NAME] ??= new self([
@@ -109,7 +103,6 @@ public static function includeDirective(): Directive
109103
]);
110104
}
111105

112-
/** @throws InvariantViolation */
113106
public static function skipDirective(): Directive
114107
{
115108
return self::$internalDirectives[self::SKIP_NAME] ??= new self([
@@ -129,7 +122,6 @@ public static function skipDirective(): Directive
129122
]);
130123
}
131124

132-
/** @throws InvariantViolation */
133125
public static function deprecatedDirective(): Directive
134126
{
135127
return self::$internalDirectives[self::DEPRECATED_NAME] ??= new self([
@@ -151,7 +143,6 @@ public static function deprecatedDirective(): Directive
151143
]);
152144
}
153145

154-
/** @throws InvariantViolation */
155146
public static function isSpecifiedDirective(Directive $directive): bool
156147
{
157148
return array_key_exists($directive->name, self::getInternalDirectives());

src/Type/Definition/Type.php

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,56 +37,58 @@ abstract class Type implements \JsonSerializable
3737
protected static ?array $builtInTypes;
3838

3939
/**
40-
* @api
40+
* Returns the registered or default standard Int type.
4141
*
42-
* @throws InvariantViolation
42+
* @api
4343
*/
4444
public static function int(): ScalarType
4545
{
46-
return static::$standardTypes[self::INT] ??= new IntType();
46+
return static::$standardTypes[self::INT] ??= new IntType(); // @phpstan-ignore missingType.checkedException (static configuration is known to be correct)
4747
}
4848

4949
/**
50-
* @api
50+
* Returns the registered or default standard Float type.
5151
*
52-
* @throws InvariantViolation
52+
* @api
5353
*/
5454
public static function float(): ScalarType
5555
{
56-
return static::$standardTypes[self::FLOAT] ??= new FloatType();
56+
return static::$standardTypes[self::FLOAT] ??= new FloatType(); // @phpstan-ignore missingType.checkedException (static configuration is known to be correct)
5757
}
5858

5959
/**
60-
* @api
60+
* Returns the registered or default standard String type.
6161
*
62-
* @throws InvariantViolation
62+
* @api
6363
*/
6464
public static function string(): ScalarType
6565
{
66-
return static::$standardTypes[self::STRING] ??= new StringType();
66+
return static::$standardTypes[self::STRING] ??= new StringType(); // @phpstan-ignore missingType.checkedException (static configuration is known to be correct)
6767
}
6868

6969
/**
70-
* @api
70+
* Returns the registered or default standard Boolean type.
7171
*
72-
* @throws InvariantViolation
72+
* @api
7373
*/
7474
public static function boolean(): ScalarType
7575
{
76-
return static::$standardTypes[self::BOOLEAN] ??= new BooleanType();
76+
return static::$standardTypes[self::BOOLEAN] ??= new BooleanType(); // @phpstan-ignore missingType.checkedException (static configuration is known to be correct)
7777
}
7878

7979
/**
80-
* @api
80+
* Returns the registered or default standard ID type.
8181
*
82-
* @throws InvariantViolation
82+
* @api
8383
*/
8484
public static function id(): ScalarType
8585
{
86-
return static::$standardTypes[self::ID] ??= new IDType();
86+
return static::$standardTypes[self::ID] ??= new IDType(); // @phpstan-ignore missingType.checkedException (static configuration is known to be correct)
8787
}
8888

8989
/**
90+
* Wraps the given type in a list type.
91+
*
9092
* @template T of Type
9193
*
9294
* @param T|callable():T $type
@@ -101,6 +103,8 @@ public static function listOf($type): ListOfType
101103
}
102104

103105
/**
106+
* Wraps the given type in a non-null type.
107+
*
104108
* @param (NullableType&Type)|callable():(NullableType&Type) $type
105109
*
106110
* @api
@@ -113,8 +117,6 @@ public static function nonNull($type): NonNull
113117
/**
114118
* Returns all builtin in types including base scalar and introspection types.
115119
*
116-
* @throws InvariantViolation
117-
*
118120
* @return array<string, Type&NamedType>
119121
*/
120122
public static function builtInTypes(): array
@@ -128,8 +130,6 @@ public static function builtInTypes(): array
128130
/**
129131
* Returns all builtin scalar types.
130132
*
131-
* @throws InvariantViolation
132-
*
133133
* @return array<string, ScalarType>
134134
*/
135135
public static function getStandardTypes(): array
@@ -144,6 +144,8 @@ public static function getStandardTypes(): array
144144
}
145145

146146
/**
147+
* Allows partially or completely overriding the standard types.
148+
*
147149
* @param array<ScalarType> $types
148150
*
149151
* @throws InvariantViolation
@@ -174,6 +176,8 @@ public static function overrideStandardTypes(array $types): void
174176
}
175177

176178
/**
179+
* Determines if the given type is an input type.
180+
*
177181
* @param mixed $type
178182
*
179183
* @api
@@ -184,6 +188,8 @@ public static function isInputType($type): bool
184188
}
185189

186190
/**
191+
* Returns the underlying named type of the given type.
192+
*
187193
* @return (Type&NamedType)|null
188194
*
189195
* @api
@@ -200,6 +206,8 @@ public static function getNamedType(?Type $type): ?Type
200206
}
201207

202208
/**
209+
* Determines if the given type is an output type.
210+
*
203211
* @param mixed $type
204212
*
205213
* @api
@@ -210,6 +218,8 @@ public static function isOutputType($type): bool
210218
}
211219

212220
/**
221+
* Determines if the given type is a leaf type.
222+
*
213223
* @param mixed $type
214224
*
215225
* @api
@@ -220,6 +230,8 @@ public static function isLeafType($type): bool
220230
}
221231

222232
/**
233+
* Determines if the given type is a composite type.
234+
*
223235
* @param mixed $type
224236
*
225237
* @api
@@ -230,6 +242,8 @@ public static function isCompositeType($type): bool
230242
}
231243

232244
/**
245+
* Determines if the given type is an abstract type.
246+
*
233247
* @param mixed $type
234248
*
235249
* @api
@@ -240,6 +254,8 @@ public static function isAbstractType($type): bool
240254
}
241255

242256
/**
257+
* Unwraps a potentially non-null type to return the underlying nullable type.
258+
*
243259
* @return Type&NullableType
244260
*
245261
* @api

0 commit comments

Comments
 (0)