Skip to content

Commit f019a88

Browse files
authored
PHPStan level 6 (#1039)
1 parent 7cd7412 commit f019a88

File tree

109 files changed

+1890
-2056
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1890
-2056
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ You can find and compare releases at the [GitHub release page](https://github.co
2929
- Call previously unused methods `EnumType::parseValue()` and `EnumType::parseLiteral()`
3030
- Strongly type `PromiseAdapter::createRejected()` to require `\Throwable`
3131
- Move members specific to `NamedType` out of `Type`: `$name`, `$description`, `$config`, `isBuiltInType()`, `assertValid()`
32+
- Always convert recursively when calling `Node::toArray()`
33+
- Make `Directive::$config['args']` use the same definition style as `FieldDefinition::$config['args']`
34+
- Rename `FieldArgument` to `Argument`
3235

3336
### Added
3437

@@ -42,6 +45,7 @@ You can find and compare releases at the [GitHub release page](https://github.co
4245
- Add SDL validation rule `UniqueOperationTypes` (#995)
4346
- Add ability to remove custom validation rules after adding them via `DocumentValidator::removeRule()`
4447
- Allow lazy enum values
48+
- Make `Node` implement `JsonSerializable`
4549

4650
### Optimized
4751

@@ -91,6 +95,8 @@ You can find and compare releases at the [GitHub release page](https://github.co
9195
- Remove `WrappingType::getWrappedType()` argument `$recurse` in favor of `WrappingType::getInnermostType()`
9296
- Remove `Type::assertType()`
9397
- Remove `ListOfType::$ofType`, `ListOfType::getOfType()` and `NonNull::getOfType()`
98+
- Remove option `commentDescriptions` from `BuildSchema::buildAST()`, `BuildSchema::build()` and `Printer::doPrint()`
99+
- Remove parameter `$options` from `ASTDefinitionBuilder`
94100

95101
## 14.11.3
96102

benchmarks/Utils/SchemaGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ protected function createFieldArgs(string $fieldName, string $typeName): array
178178
}
179179

180180
/**
181+
* @param mixed $root
181182
* @param array<string, mixed> $args
183+
* @param mixed $context
182184
*/
183185
public function resolveField($root, array $args, $context, ResolveInfo $resolveInfo): string
184186
{

docs/type-definitions/directives.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ In **graphql-php** custom directive is an instance of `GraphQL\Type\Definition\D
3838
use GraphQL\Language\DirectiveLocation;
3939
use GraphQL\Type\Definition\Type;
4040
use GraphQL\Type\Definition\Directive;
41-
use GraphQL\Type\Definition\FieldArgument;
4241

4342
$trackDirective = new Directive([
4443
'name' => 'track',
@@ -47,12 +46,11 @@ $trackDirective = new Directive([
4746
DirectiveLocation::FIELD,
4847
],
4948
'args' => [
50-
new FieldArgument([
51-
'name' => 'details',
49+
'details' => [
5250
'type' => Type::string(),
5351
'description' => 'String with additional details of field usage scenario',
5452
'defaultValue' => ''
55-
])
53+
]
5654
]
5755
]);
5856
```

examples/01-blog/Blog/Type/CommentType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use GraphQL\Examples\Blog\Data\User;
1010
use GraphQL\Examples\Blog\Type\Field\HtmlField;
1111
use GraphQL\Examples\Blog\Types;
12+
use GraphQL\Type\Definition\ListOfType;
1213
use GraphQL\Type\Definition\ObjectType;
1314
use GraphQL\Type\Definition\ResolveInfo;
1415

@@ -27,7 +28,7 @@ public function __construct()
2728
'parent' => Types::comment(),
2829
'isAnonymous' => Types::boolean(),
2930
'replies' => [
30-
'type' => Types::listOf(Types::comment()),
31+
'type' => new ListOfType(Types::comment()),
3132
'args' => [
3233
'after' => Types::int(),
3334
'limit' => [

examples/01-blog/Blog/Type/ImageType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use GraphQL\Examples\Blog\AppContext;
99
use GraphQL\Examples\Blog\Data\Image;
1010
use GraphQL\Examples\Blog\Types;
11+
use GraphQL\Type\Definition\NonNull;
1112
use GraphQL\Type\Definition\ObjectType;
1213
use GraphQL\Type\Definition\ResolveInfo;
1314
use UnexpectedValueException;
@@ -36,7 +37,7 @@ public function __construct()
3637
},
3738
],
3839
'nonNullFieldWithError' => [
39-
'type' => Types::nonNull(Types::string()),
40+
'type' => new NonNull(Types::string()),
4041
'resolve' => static function (): void {
4142
throw new Exception('Non-null field with exception');
4243
},

examples/01-blog/Blog/Type/QueryType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use GraphQL\Examples\Blog\Data\Story;
1111
use GraphQL\Examples\Blog\Data\User;
1212
use GraphQL\Examples\Blog\Types;
13+
use GraphQL\Type\Definition\ListOfType;
14+
use GraphQL\Type\Definition\NonNull;
1315
use GraphQL\Type\Definition\ObjectType;
1416
use GraphQL\Type\Definition\ResolveInfo;
1517
use GraphQL\Type\Definition\Type;
@@ -25,15 +27,15 @@ public function __construct()
2527
'type' => Types::user(),
2628
'description' => 'Returns user by id (in range of 1-5)',
2729
'args' => [
28-
'id' => Types::nonNull(Types::id()),
30+
'id' => new NonNull(Types::id()),
2931
],
3032
],
3133
'viewer' => [
3234
'type' => Types::user(),
3335
'description' => 'Represents currently logged-in user (for the sake of example - simply returns user with id == 1)',
3436
],
3537
'stories' => [
36-
'type' => Types::listOf(Types::story()),
38+
'type' => new ListOfType(Types::story()),
3739
'description' => 'Returns subset of stories posted for this blog',
3840
'args' => [
3941
'after' => [

examples/01-blog/Blog/Type/StoryType.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use GraphQL\Examples\Blog\Data\User;
1212
use GraphQL\Examples\Blog\Type\Field\HtmlField;
1313
use GraphQL\Examples\Blog\Types;
14+
use GraphQL\Type\Definition\ListOfType;
1415
use GraphQL\Type\Definition\ObjectType;
1516
use GraphQL\Type\Definition\ResolveInfo;
1617

@@ -26,10 +27,10 @@ public function __construct()
2627
'fields' => static fn (): array => [
2728
'id' => Types::id(),
2829
'author' => Types::user(),
29-
'mentions' => Types::listOf(Types::mention()),
30+
'mentions' => new ListOfType(Types::mention()),
3031
'totalCommentCount' => Types::int(),
3132
'comments' => [
32-
'type' => Types::listOf(Types::comment()),
33+
'type' => new ListOfType(Types::comment()),
3334
'args' => [
3435
'after' => [
3536
'type' => Types::id(),
@@ -42,7 +43,7 @@ public function __construct()
4243
],
4344
],
4445
'likes' => [
45-
'type' => Types::listOf(Types::user()),
46+
'type' => new ListOfType(Types::user()),
4647
'args' => [
4748
'limit' => [
4849
'type' => Types::int(),
@@ -51,8 +52,8 @@ public function __construct()
5152
],
5253
],
5354
],
54-
'likedBy' => Types::listOf(Types::user()),
55-
'affordances' => Types::listOf(Types::storyAffordances()),
55+
'likedBy' => new ListOfType(Types::user()),
56+
'affordances' => new ListOfType(Types::storyAffordances()),
5657
'hasViewerLiked' => Types::boolean(),
5758

5859
'body' => HtmlField::build('body'),

examples/01-blog/Blog/Type/UserType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
use Exception;
88
use GraphQL\Examples\Blog\Data\DataSource;
99
use GraphQL\Examples\Blog\Data\Image;
10+
use GraphQL\Examples\Blog\Data\Story;
1011
use GraphQL\Examples\Blog\Data\User;
1112
use GraphQL\Examples\Blog\Types;
13+
use GraphQL\Type\Definition\NonNull;
1214
use GraphQL\Type\Definition\ObjectType;
1315
use GraphQL\Type\Definition\ResolveInfo;
1416

@@ -29,7 +31,7 @@ public function __construct()
2931
'type' => Types::image(),
3032
'description' => 'User photo URL',
3133
'args' => [
32-
'size' => Types::nonNull(Types::imageSize()),
34+
'size' => new NonNull(Types::imageSize()),
3335
],
3436
],
3537
'firstName' => [
@@ -68,7 +70,7 @@ public function resolvePhoto(User $user, array $args): Image
6870
return DataSource::getUserPhoto($user->id, $args['size']);
6971
}
7072

71-
public function resolveLastStoryPosted(User $user)
73+
public function resolveLastStoryPosted(User $user): ?Story
7274
{
7375
return DataSource::findLastStoryFor($user->id);
7476
}

examples/01-blog/Blog/Types.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
use GraphQL\Examples\Blog\Type\SearchResultType;
1818
use GraphQL\Examples\Blog\Type\StoryType;
1919
use GraphQL\Examples\Blog\Type\UserType;
20-
use GraphQL\Type\Definition\ListOfType;
21-
use GraphQL\Type\Definition\NonNull;
2220
use GraphQL\Type\Definition\ScalarType;
2321
use GraphQL\Type\Definition\Type;
2422

@@ -173,20 +171,4 @@ public static function string(): ScalarType
173171
{
174172
return Type::string();
175173
}
176-
177-
/**
178-
* @param Type|callable():Type $type
179-
*/
180-
public static function listOf($type): ListOfType
181-
{
182-
return new ListOfType($type);
183-
}
184-
185-
/**
186-
* @param Type|callable():Type $type
187-
*/
188-
public static function nonNull($type): NonNull
189-
{
190-
return new NonNull($type);
191-
}
192174
}

generate-class-reference.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
];
6565

6666
/**
67+
* @param ReflectionClass<object> $class
6768
* @param array{constants?: bool, props?: bool, methods?: bool} $options
6869
*/
6970
function renderClass(ReflectionClass $class, array $options): string

0 commit comments

Comments
 (0)