Skip to content

Commit db1385b

Browse files
authored
Merge pull request #485 from mxr576/issue/478
Replace deprecated PHPStan\Type\Constant\ConstantArrayType::findTypeAndMethodName() call
2 parents d2411d6 + d0bf4d3 commit db1385b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
"squizlabs/php_codesniffer": "^3.3",
3030
"symfony/phpunit-bridge": "^3.4.3 || ^4.4 || ^5.4 || ^6.0"
3131
},
32+
"conflict": {
33+
"phpstan/phpstan": "^2.0"
34+
},
3235
"minimum-stability": "dev",
3336
"prefer-stable": true,
3437
"suggest": {

src/Rules/Drupal/RenderCallbackRule.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,17 @@ private function doProcessNode(Node\Expr $node, Scope $scope, string $keyChecked
160160
sprintf("%s callback %s at key '%s' is not callable.", $keyChecked, $type->describe(VerbosityLevel::value()), $pos)
161161
)->line($errorLine)->build();
162162
}
163-
$typeAndMethodName = $type->findTypeAndMethodName();
164-
if ($typeAndMethodName === null) {
163+
$typeAndMethodNames = $type->findTypeAndMethodNames();
164+
if ($typeAndMethodNames === []) {
165165
throw new \PHPStan\ShouldNotHappenException();
166166
}
167167

168-
if (!$trustedCallbackType->isSuperTypeOf($typeAndMethodName->getType())->yes()) {
169-
return RuleErrorBuilder::message(
170-
sprintf("%s callback class '%s' at key '%s' does not implement Drupal\Core\Security\TrustedCallbackInterface.", $keyChecked, $typeAndMethodName->getType()->describe(VerbosityLevel::value()), $pos)
171-
)->line($errorLine)->tip('Change record: https://www.drupal.org/node/2966725.')->build();
168+
foreach ($typeAndMethodNames as $typeAndMethodName) {
169+
if (!$trustedCallbackType->isSuperTypeOf($typeAndMethodName->getType())->yes()) {
170+
return RuleErrorBuilder::message(
171+
sprintf("%s callback class '%s' at key '%s' does not implement Drupal\Core\Security\TrustedCallbackInterface.", $keyChecked, $typeAndMethodName->getType()->describe(VerbosityLevel::value()), $pos)
172+
)->line($errorLine)->tip('Change record: https://www.drupal.org/node/2966725.')->build();
173+
}
172174
}
173175
} elseif ($type instanceof ClosureType) {
174176
if ($scope->isInClass()) {
@@ -219,6 +221,7 @@ private function getType(Node\Expr $node, Scope $scope): Type
219221
}
220222
}
221223
} elseif ($type instanceof ConstantStringType) {
224+
// @phpstan-ignore-next-line
222225
if ($type->isClassString()) {
223226
return $type;
224227
}

0 commit comments

Comments
 (0)