Skip to content

Commit 515749e

Browse files
committed
Fix phpstan inspection failures
1 parent d087a5c commit 515749e

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

src/Rules/Drupal/LoadIncludes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,17 @@ public function processNode(Node $node, Scope $scope): array
7373
$extensionDiscovery = new ExtensionDiscovery($drupal_root);
7474
$modules = $extensionDiscovery->scan('module');
7575
$module_arg = $node->args[0];
76+
assert($module_arg instanceof Node\Arg);
7677
assert($module_arg->value instanceof Node\Scalar\String_);
7778
$type_arg = $node->args[1];
79+
assert($type_arg instanceof Node\Arg);
7880
assert($type_arg->value instanceof Node\Scalar\String_);
7981
$name_arg = $node->args[2] ?? null;
8082

8183
if ($name_arg === null) {
8284
$name_arg = $module_arg;
8385
}
86+
assert($name_arg instanceof Node\Arg);
8487
assert($name_arg->value instanceof Node\Scalar\String_);
8588

8689
$module_name = $module_arg->value->value;

src/Rules/Drupal/ModuleLoadInclude.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function processNode(Node $node, Scope $scope): array
4848
if ($name !== 'module_load_include') {
4949
return [];
5050
}
51-
$stop = null;
5251

5352
try {
5453
// Try to invoke it similarily as the module handler itself.
@@ -58,14 +57,17 @@ public function processNode(Node $node, Scope $scope): array
5857
$extensionDiscovery = new ExtensionDiscovery($drupal_root);
5958
$modules = $extensionDiscovery->scan('module');
6059
$type_arg = $node->args[0];
60+
assert($type_arg instanceof Node\Arg);
6161
assert($type_arg->value instanceof Node\Scalar\String_);
6262
$module_arg = $node->args[1];
63+
assert($module_arg instanceof Node\Arg);
6364
assert($module_arg->value instanceof Node\Scalar\String_);
6465
$name_arg = $node->args[2] ?? null;
6566

6667
if ($name_arg === null) {
6768
$name_arg = $module_arg;
6869
}
70+
assert($name_arg instanceof Node\Arg);
6971
assert($name_arg->value instanceof Node\Scalar\String_);
7072

7173
$module_name = $module_arg->value->value;

src/Rules/Drupal/PluginManager/PluginManagerSetsCacheBackendRule.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,19 @@ public function processNode(Node $node, Scope $scope): array
6161
// setCacheBackend accepts a cache backend, the cache key, and optional (but suggested) cache tags.
6262
$setCacheBackendArgs = $statement->args;
6363

64+
if ($setCacheBackendArgs[1] instanceof Node\VariadicPlaceholder) {
65+
throw new ShouldNotHappenException();
66+
}
6467
$cacheKey = $setCacheBackendArgs[1]->value;
6568
if (!$cacheKey instanceof Node\Scalar\String_) {
6669
continue;
6770
}
6871
$hasCacheBackendSet = true;
6972

7073
if (isset($setCacheBackendArgs[2])) {
74+
if ($setCacheBackendArgs[2] instanceof Node\VariadicPlaceholder) {
75+
throw new ShouldNotHappenException();
76+
}
7177
/** @var \PhpParser\Node\Expr\Array_ $cacheTags */
7278
$cacheTags = $setCacheBackendArgs[2]->value;
7379
if (count($cacheTags->items) > 0) {

src/Type/EntityTypeManagerGetStorageDynamicReturnTypeExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node\Expr\BinaryOp\Concat;
66
use PhpParser\Node\Expr\MethodCall;
77
use PhpParser\Node\Scalar\String_;
8+
use PhpParser\Node\VariadicPlaceholder;
89
use PHPStan\Analyser\Scope;
910
use PHPStan\Reflection\MethodReflection;
1011
use PHPStan\Reflection\ParametersAcceptorSelector;
@@ -48,7 +49,11 @@ public function getTypeFromMethodCall(
4849
throw new ShouldNotHappenException();
4950
}
5051

51-
$arg1 = $methodCall->args[0]->value;
52+
$arg1 = $methodCall->args[0];
53+
if ($arg1 instanceof VariadicPlaceholder) {
54+
throw new ShouldNotHappenException();
55+
}
56+
$arg1 = $arg1->value;
5257

5358
// @todo handle where the first param is EntityTypeInterface::id()
5459
if ($arg1 instanceof MethodCall) {

src/Type/ServiceDynamicReturnTypeExtension.php

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

55
use PhpParser\Node\Expr\MethodCall;
66
use PhpParser\Node\Scalar\String_;
7+
use PhpParser\Node\VariadicPlaceholder;
78
use PHPStan\Analyser\Scope;
89
use PHPStan\Drupal\DrupalServiceDefinition;
910
use PHPStan\Drupal\ServiceMap;
@@ -45,7 +46,11 @@ public function getTypeFromMethodCall(
4546
return $returnType;
4647
}
4748

48-
$arg1 = $methodCall->args[0]->value;
49+
$arg1 = $methodCall->args[0];
50+
if ($arg1 instanceof VariadicPlaceholder) {
51+
throw new ShouldNotHappenException();
52+
}
53+
$arg1 = $arg1->value;
4954
if (!$arg1 instanceof String_) {
5055
// @todo determine what these types are.
5156
return $returnType;

0 commit comments

Comments
 (0)