Skip to content

Commit 09b81c8

Browse files
spawniasimPod
andauthored
PHPStan level 7 (#1045)
Co-authored-by: Simon Podlipsky <[email protected]>
1 parent 07c5897 commit 09b81c8

File tree

170 files changed

+1590
-1722
lines changed

Some content is hidden

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

170 files changed

+1590
-1722
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You can find and compare releases at the [GitHub release page](https://github.co
1717
- Use native PHP types for properties of `Type` and its subclasses
1818
- Throw `SerializationError` over client safe `Error` when failing to serialize leaf types
1919
- Move debug entries in errors under `extensions` key
20-
- Use native PHP types for `Schema` and `SchemaConfig`
20+
- Use native PHP types wherever possible
2121
- Always throw `RequestError` with useful message when clients provide an invalid JSON body
2222
- Move class `BlockString` from namespace `GraphQL\Utils` to `GraphQL\Language`
2323
- Return string-keyed arrays from `GraphQL::getStandardDirectives()`, `GraphQL::getStandardTypes()` and `GraphQL::getStandardValidationRules()`
@@ -32,6 +32,11 @@ You can find and compare releases at the [GitHub release page](https://github.co
3232
- Always convert recursively when calling `Node::toArray()`
3333
- Make `Directive::$config['args']` use the same definition style as `FieldDefinition::$config['args']`
3434
- Rename `FieldArgument` to `Argument`
35+
- Make errors when parsing scalar literals more precise
36+
- Change expected `QueryPlan` options from `['group-implementor-fields']` to `['groupImplementorFields' => true]` in `ResolveInfo::lookAhead()`
37+
- Always convert promises through `PromiseAdapter::convertThenable()` before calling `->then()` on them
38+
- Use `JSON_THROW_ON_ERROR` in `json_encode()`
39+
- Validate some internal invariants through `assert()`
3540

3641
### Added
3742

@@ -97,6 +102,7 @@ You can find and compare releases at the [GitHub release page](https://github.co
97102
- Remove `ListOfType::$ofType`, `ListOfType::getOfType()` and `NonNull::getOfType()`
98103
- Remove option `commentDescriptions` from `BuildSchema::buildAST()`, `BuildSchema::build()` and `Printer::doPrint()`
99104
- Remove parameter `$options` from `ASTDefinitionBuilder`
105+
- Remove `FieldDefinition::create()` in favor of `new FieldDefinition()`
100106

101107
## 14.11.3
102108

benchmarks/Utils/SchemaGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected function createType(int $nestingLevel, ?string $typeName = null): Obje
8989
}
9090

9191
/**
92-
* @return array{0: ObjectType, 1: string}
92+
* @return array{0: Type, 1: string}
9393
*/
9494
protected function getFieldTypeAndName(int $nestingLevel, int $fieldIndex): array
9595
{

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"psr/http-message": "^1",
3030
"react/promise": "^2",
3131
"symfony/polyfill-php81": "^1.23",
32-
"symfony/var-exporter": "^5.3"
32+
"symfony/var-exporter": "^5.3",
33+
"thecodingmachine/safe": "^1.3"
3334
},
3435
"suggest": {
3536
"psr/http-message": "To use standard GraphQL server",

docs/class-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2346,7 +2346,7 @@ static function toArray(GraphQL\Language\AST\Node $node): array
23462346
* | null | NullValue |
23472347
*
23482348
* @param Type|mixed|null $value
2349-
* @param ScalarType|EnumType|InputObjectType|ListOfType<Type &InputType>|NonNull $type
2349+
* @param ScalarType|EnumType|InputObjectType|ListOfType<Type&InputType>|NonNull $type
23502350
*
23512351
* @return ObjectValueNode|ListValueNode|BooleanValueNode|IntValueNode|FloatValueNode|EnumValueNode|StringValueNode|NullValueNode|null
23522352
*

examples/00-hello-world/graphql.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
]);
5959

6060
$rawInput = file_get_contents('php://input');
61+
if (false === $rawInput) {
62+
throw new RuntimeException('Failed to get php://input');
63+
}
64+
6165
$input = json_decode($rawInput, true);
6266
$query = $input['query'];
6367
$variableValues = $input['variables'] ?? null;

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
namespace GraphQL\Examples\Blog\Type;
66

77
use Exception;
8-
use function get_class;
98
use GraphQL\Examples\Blog\Data\Image;
109
use GraphQL\Examples\Blog\Data\Story;
1110
use GraphQL\Examples\Blog\Data\User;
1211
use GraphQL\Examples\Blog\Types;
1312
use GraphQL\Type\Definition\InterfaceType;
14-
use GraphQL\Type\Definition\Type;
13+
use GraphQL\Type\Definition\ObjectType;
14+
use GraphQL\Utils\Utils;
1515

1616
class NodeType extends InterfaceType
1717
{
@@ -26,7 +26,12 @@ public function __construct()
2626
]);
2727
}
2828

29-
public function resolveNodeType(object $object): Type
29+
/**
30+
* @param mixed $object
31+
*
32+
* @return callable(): ObjectType
33+
*/
34+
public function resolveNodeType($object)
3035
{
3136
if ($object instanceof User) {
3237
return Types::user();
@@ -40,6 +45,6 @@ public function resolveNodeType(object $object): Type
4045
return Types::story();
4146
}
4247

43-
throw new Exception('Unknown type: ' . get_class($object));
48+
throw new Exception('Unknown type: ' . Utils::printSafe($object));
4449
}
4550
}

examples/01-blog/Blog/Type/Scalar/UrlType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public function parseLiteral(Node $valueNode, ?array $variables = null): string
5757
private function isUrl($value): bool
5858
{
5959
return is_string($value)
60-
&& filter_var($value, FILTER_VALIDATE_URL);
60+
&& false !== filter_var($value, FILTER_VALIDATE_URL);
6161
}
6262
}

examples/01-blog/Blog/Types.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace GraphQL\Examples\Blog;
66

7-
use function class_exists;
87
use Closure;
98
use function count;
109
use Exception;
@@ -94,35 +93,29 @@ public static function url(): callable
9493
}
9594

9695
/**
96+
* @param class-string<Type> $classname
97+
*
9798
* @return Closure(): Type
9899
*/
99100
private static function get(string $classname): Closure
100101
{
101102
return static fn () => self::byClassName($classname);
102103
}
103104

105+
/**
106+
* @param class-string<Type> $classname
107+
*/
104108
private static function byClassName(string $classname): Type
105109
{
106110
$parts = explode('\\', $classname);
107111

108112
$cacheName = strtolower(preg_replace('~Type$~', '', $parts[count($parts) - 1]));
109-
$type = null;
110113

111114
if (! isset(self::$types[$cacheName])) {
112-
if (class_exists($classname)) {
113-
$type = new $classname();
114-
}
115-
116-
self::$types[$cacheName] = $type;
115+
return self::$types[$cacheName] = new $classname();
117116
}
118117

119-
$type = self::$types[$cacheName];
120-
121-
if (! $type) {
122-
throw new Exception('Unknown graphql type: ' . $classname);
123-
}
124-
125-
return $type;
118+
return self::$types[$cacheName];
126119
}
127120

128121
public static function byTypeName(string $shortName): Type

examples/02-schema-definition-language/graphql.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
];
3434

3535
$rawInput = file_get_contents('php://input');
36+
if (false === $rawInput) {
37+
throw new RuntimeException('Failed to get php://input');
38+
}
39+
3640
$input = json_decode($rawInput, true);
3741
$query = $input['query'];
3842
$variableValues = $input['variables'] ?? null;

generate-class-reference.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,9 @@ function renderProp(ReflectionProperty $prop): string
174174
return unpadDocblock($prop->getDocComment()) . "\n" . $signature;
175175
}
176176

177-
/**
178-
* @param string|false $docBlock
179-
*/
180-
function unwrapDocblock($docBlock): string
177+
function unwrapDocblock(string $docBlock): string
181178
{
182-
if (! $docBlock) {
179+
if ('' === $docBlock) {
183180
return '';
184181
}
185182

@@ -196,7 +193,7 @@ function unwrapDocblock($docBlock): string
196193
*/
197194
function unpadDocblock($docBlock): string
198195
{
199-
if (! $docBlock) {
196+
if (false === $docBlock) {
200197
return '';
201198
}
202199

@@ -215,7 +212,7 @@ function unpadDocblock($docBlock): string
215212
function isApi(Reflector $reflector): bool
216213
{
217214
$comment = $reflector->getDocComment();
218-
if (! $comment) {
215+
if (false === $comment) {
219216
return false;
220217
}
221218

0 commit comments

Comments
 (0)