Skip to content

Commit cf0c693

Browse files
authored
Increase PHPStan analysis level to 8 (#1059)
1 parent c55aa79 commit cf0c693

File tree

109 files changed

+1474
-1253
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

+1474
-1253
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ You can find and compare releases at the [GitHub release page](https://github.co
3838
- Use `JSON_THROW_ON_ERROR` in `json_encode()`
3939
- Validate some internal invariants through `assert()`
4040
- `PromiseAdapter::all()` accepts `iterable`
41+
- Throw if `Introspection::fromSchema()` returns no data
42+
- Reorganize abstract class `ASTValidationContext` to interface `ValidationContext`
4143

4244
### Added
4345

@@ -69,6 +71,7 @@ You can find and compare releases at the [GitHub release page](https://github.co
6971
- Fix printing of empty types (#940)
7072
- Clone `NodeList` in `Node::cloneDeep()`
7173
- Calling `Schema::getType()` on a schema built from SDL returns `null` for unknown types (#1068)
74+
- Avoid crash on typeless inline fragment when using `QueryComplexity` rule
7275

7376
### Removed
7477

@@ -105,6 +108,7 @@ You can find and compare releases at the [GitHub release page](https://github.co
105108
- Remove option `commentDescriptions` from `BuildSchema::buildAST()`, `BuildSchema::build()` and `Printer::doPrint()`
106109
- Remove parameter `$options` from `ASTDefinitionBuilder`
107110
- Remove `FieldDefinition::create()` in favor of `new FieldDefinition()`
111+
- Remove `GraphQL\Exception\InvalidArgument`
108112

109113
## 14.11.5
110114

benchmarks/Utils/QueryGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use GraphQL\Type\Definition\ObjectType;
1616
use GraphQL\Type\Definition\Type;
1717
use GraphQL\Type\Schema;
18-
use GraphQL\Utils\Utils;
1918
use function max;
2019
use function round;
2120

@@ -31,7 +30,7 @@ public function __construct(Schema $schema, float $percentOfLeafFields)
3130
{
3231
$this->schema = $schema;
3332

34-
Utils::invariant(0 < $percentOfLeafFields && $percentOfLeafFields <= 1);
33+
assert(0 < $percentOfLeafFields && $percentOfLeafFields <= 1);
3534

3635
$totalFields = 0;
3736
foreach ($schema->getTypeMap() as $type) {
@@ -47,6 +46,7 @@ public function __construct(Schema $schema, float $percentOfLeafFields)
4746
public function buildQuery(): string
4847
{
4948
$queryType = $this->schema->getQueryType();
49+
assert($queryType instanceof ObjectType);
5050

5151
$ast = new DocumentNode([
5252
'definitions' => new NodeList([

docs/security.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ $type = new ObjectType([
4242
'defaultValue' => 10
4343
]
4444
],
45-
'complexity' => function($childrenComplexity, $args) {
46-
return $childrenComplexity * $args['limit'];
47-
}
45+
'complexity' => fn (int $childrenComplexity, array $args): int => $childrenComplexity * $args['limit'],
4846
]
4947
]
5048
]);

examples/01-blog/Blog/Types.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ private static function byClassName(string $classname): Type
107107
{
108108
$parts = explode('\\', $classname);
109109

110-
$cacheName = strtolower(preg_replace('~Type$~', '', $parts[count($parts) - 1]));
110+
$withoutTypePrefix = preg_replace('~Type$~', '', $parts[count($parts) - 1]);
111+
assert(is_string($withoutTypePrefix), 'regex is statically known to be correct');
112+
113+
$cacheName = strtolower($withoutTypePrefix);
111114

112115
if (! isset(self::$types[$cacheName])) {
113116
return self::$types[$cacheName] = new $classname();

examples/01-blog/graphql.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
// Prepare context that will be available in all field resolvers (as 3rd argument):
3131
$appContext = new AppContext();
32-
$appContext->viewer = DataSource::findUser(1); // simulated "currently logged-in user"
32+
$currentlyLoggedInUser = DataSource::findUser(1);
33+
assert(null !== $currentlyLoggedInUser);
34+
$appContext->viewer = $currentlyLoggedInUser;
3335
$appContext->rootUrl = 'http://localhost:8080';
3436
$appContext->request = $_REQUEST;
3537

generate-class-reference.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ function unwrapDocblock(string $docBlock): string
175175
}
176176

177177
$content = preg_replace('~([\r\n]) \* (.*)~i', '$1$2', $docBlock); // strip *
178+
assert(is_string($content), 'regex is statically known to be valid');
179+
178180
$content = preg_replace('~([\r\n])[\* ]+([\r\n])~i', '$1$2', $content); // strip single-liner *
181+
assert(is_string($content), 'regex is statically known to be valid');
182+
179183
$content = substr($content, 3); // strip leading /**
180184
$content = substr($content, 0, -2); // strip trailing */
181185

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ parameters:
7575
count: 1
7676
path: src/Language/Printer.php
7777

78-
-
79-
message: "#^Strict comparison using \\=\\=\\= between mixed and null will always evaluate to false\\.$#"
80-
count: 1
81-
path: src/Language/Visitor.php
82-
8378
-
8479
message: "#^Variable property access on GraphQL\\\\Language\\\\AST\\\\Node\\.$#"
8580
count: 1

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
parameters:
22
# TODO increase to max
3-
level: 7
3+
level: 8
44

55
paths:
66
- benchmarks

src/Error/FormattedError.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ public static function printError(Error $error): string
6464
$nodes = $error->nodes;
6565
if (isset($nodes) && count($nodes) > 0) {
6666
foreach ($nodes as $node) {
67-
if (isset($node->loc->source)) {
68-
$location = $node->loc;
67+
$location = $node->loc;
68+
if (isset($location)) {
6969
$source = $location->source;
70-
$printedLocations[] = self::highlightSourceAtLocation(
71-
$source,
72-
$source->getLocation($location->start)
73-
);
70+
if (isset($source)) {
71+
$printedLocations[] = self::highlightSourceAtLocation(
72+
$source,
73+
$source->getLocation($location->start)
74+
);
75+
}
7476
}
7577
}
7678
} elseif (null !== $error->getSource() && 0 !== count($error->getLocations())) {

src/Error/InvariantViolation.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,4 @@
1111
*/
1212
class InvariantViolation extends LogicException
1313
{
14-
public static function shouldNotHappen(): self
15-
{
16-
return new self('This should not have happened');
17-
}
1814
}

0 commit comments

Comments
 (0)