Skip to content

Commit 4661624

Browse files
authored
test(phpstan): Update and simplify PHPStan config options (#1404)
1 parent 46a63fd commit 4661624

File tree

5 files changed

+46
-28
lines changed

5 files changed

+46
-28
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
# Pin the exact Coder version to upgrade manually when we want to.
102102
run: |
103103
composer --no-interaction --no-progress require \
104-
phpstan/phpstan:^1.10.38 \
104+
phpstan/phpstan:^1.11.2 \
105105
mglaman/phpstan-drupal:^1.1.2 \
106106
phpstan/phpstan-deprecation-rules:^1.0.0 \
107107
jangregor/phpstan-prophecy:^1.0.0 \

phpstan.neon

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
parameters:
2-
# PHPStan cannot find files in this test directory automatically.
3-
scanDirectories:
4-
- ../../core/tests/Drupal/Tests
52
level: 6
63
customRulesetUsed: true
74
paths:
85
- .
9-
# We inherit a lot of Drupal core docs that don't specify iterable types on
10-
# arrays, not sure we can fix this in a good way.
11-
checkMissingIterableValueType: false
12-
# Not sure we can specify generic types properly with Drupal coding standards
13-
# yet, disable for now.
14-
checkGenericClassInNonGenericObjectType: false
15-
excludePaths:
16-
# Exclude the RouteLoad producer because the redirect module is not D10
17-
# compatible so we are not downloading it.
18-
- src/Plugin/GraphQL/DataProducer/Routing/RouteLoad.php
196
ignoreErrors:
20-
# @todo Ignore phpstan-drupal extension's rules for now, activate later.
21-
- '#\Drupal calls should be avoided in classes, use dependency injection instead#'
7+
# We inherit a lot of Drupal core docs that don't specify iterable types on
8+
# arrays, not sure we can fix this in a good way.
9+
- identifier: missingType.iterableValue
2210
# new static() is a best practice in Drupal, so we cannot fix that.
2311
- "#^Unsafe usage of new static\\(\\)\\.$#"
24-
# Drupal allows object property access to custom fields, so we cannot fix
25-
# that.
26-
- "#^Access to an undefined property Drupal\\\\#"
2712
# We forgot to use return type hints on some interfaces, cannot be changed
2813
# in stable 4.0.
2914
# @todo use return type hints everywhere for 5.0.
@@ -51,3 +36,34 @@ parameters:
5136
message: "#^Method Drupal\\\\graphql\\\\Entity\\\\ServerInterface\\:\\:removePersistedQueryInstance\\(\\) has no return type specified\\.$#"
5237
count: 1
5338
path: src/Entity/ServerInterface.php
39+
40+
# @todo Some leftover \Drupal calls that can be fixed later.
41+
-
42+
message: "#^\\\\Drupal calls should be avoided in classes, use dependency injection instead$#"
43+
count: 1
44+
path: examples/graphql_example/src/Wrappers/QueryConnection.php
45+
46+
-
47+
message: "#^\\\\Drupal calls should be avoided in classes, use dependency injection instead$#"
48+
count: 3
49+
path: src/Controller/ServerListBuilder.php
50+
51+
-
52+
message: "#^\\\\Drupal calls should be avoided in classes, use dependency injection instead$#"
53+
count: 1
54+
path: src/GraphQL/Execution/Executor.php
55+
56+
-
57+
message: "#^\\\\Drupal calls should be avoided in classes, use dependency injection instead$#"
58+
count: 1
59+
path: src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php
60+
61+
-
62+
message: "#^\\\\Drupal calls should be avoided in classes, use dependency injection instead$#"
63+
count: 1
64+
path: src/Plugin/GraphQL/DataProducer/EntityDefinition/EntityDefinition.php
65+
66+
-
67+
message: "#^\\\\Drupal calls should be avoided in classes, use dependency injection instead$#"
68+
count: 1
69+
path: src/Plugin/GraphQL/DataProducer/User/PasswordReset.php

src/GraphQL/Buffers/BufferBase.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ abstract class BufferBase {
1010
/**
1111
* The the array of buffers.
1212
*
13-
* @var \SplObjectStorage[]
13+
* @var \SplObjectStorage<object, object>[]
1414
*/
1515
protected $buffers = [];
1616

1717
/**
1818
* The array of result sets.
1919
*
20-
* @var \SplObjectStorage[]
20+
* @var \SplObjectStorage<object, object>[]
2121
*/
2222
protected $results = [];
2323

@@ -65,9 +65,9 @@ public function createBufferResolver($item) {
6565
*
6666
* @param object $item
6767
* The item to add to create the resolver for.
68-
* @param \SplObjectStorage $buffer
68+
* @param \SplObjectStorage<object, object> $buffer
6969
* The buffer.
70-
* @param \SplObjectStorage $result
70+
* @param \SplObjectStorage<object, object> $result
7171
* The result set.
7272
*
7373
* @return \Closure
@@ -85,9 +85,9 @@ protected function createResolver($item, \SplObjectStorage $buffer, \SplObjectSt
8585
*
8686
* @param object $item
8787
* The buffer item to retrieve the result for.
88-
* @param \SplObjectStorage $buffer
88+
* @param \SplObjectStorage<object, object> $buffer
8989
* The buffer.
90-
* @param \SplObjectStorage $result
90+
* @param \SplObjectStorage<object, object> $result
9191
* The result set.
9292
*
9393
* @return mixed
@@ -112,10 +112,10 @@ protected function resolveItem($item, \SplObjectStorage $buffer, \SplObjectStora
112112
/**
113113
* Resolves the given buffer wholly.
114114
*
115-
* @param \SplObjectStorage $buffer
115+
* @param \SplObjectStorage<object, object> $buffer
116116
* The buffer to be resolved wholly.
117117
*
118-
* @return \SplObjectStorage
118+
* @return \SplObjectStorage<object, object>
119119
* The resolved results for the given buffer, keyed by the corresponding
120120
* buffer items.
121121
*/

src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable
9898
$metadata->addCacheableDependency($access);
9999
if ($access->isAllowed() && $image_style = ImageStyle::load($style)) {
100100

101+
// @phpstan-ignore-next-line
101102
$width = $entity->width;
103+
// @phpstan-ignore-next-line
102104
$height = $entity->height;
103105

104106
if (empty($width) || empty($height)) {

tests/src/Traits/MockingTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected function setUpSchema($schema, $id = 'test', array $values = []): void
106106
protected function createTestServer($schema, $endpoint, array $values = []): void {
107107
$this->server = Server::create([
108108
'schema' => $schema,
109-
'name' => $this->randomGenerator->name(),
109+
'name' => $this->randomMachineName(),
110110
'endpoint' => $endpoint,
111111
] + $values);
112112

0 commit comments

Comments
 (0)