BetterNodeFinder improvements

This commit is contained in:
TomasVotruba 2021-03-18 12:27:34 +01:00
parent e61f80bd21
commit 8685a44ed0
5 changed files with 8 additions and 7 deletions

View File

@ -202,7 +202,7 @@ final class ClassMethodReturnTypeOverrideGuard
private function hasClassMethodExprReturn(ClassMethod $classMethod): bool
{
return (bool) $this->betterNodeFinder->findFirst($classMethod->getStmts(), function (Node $node): bool {
return (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node): bool {
if (! $node instanceof Return_) {
return false;
}

View File

@ -584,3 +584,6 @@ parameters:
- '#Method Rector\\Testing\\Finder\\RectorsFinder\:\:findClassesInDirectoriesByName\(\) should return array<class\-string\> but returns array<int, string\>#'
- '#Cannot cast array<string\>\|string\|null to string#'
# phpstan bug
- '#Unable to resolve the template type T in call to method Rector\\Core\\PhpParser\\Node\\BetterNodeFinder\:\:findParentTypes\(\)#'

View File

@ -130,7 +130,7 @@ final class PromotedPropertyResolver
foreach ($classMethod->params as $param) {
$paramName = $this->nodeNameResolver->getName($param);
$firstParamVariable = $this->betterNodeFinder->findFirst($classMethod->stmts, function (Node $node) use (
$firstParamVariable = $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node) use (
$paramName
): bool {
if (! $node instanceof Variable) {

View File

@ -182,10 +182,8 @@ final class ComplexNodeRemover
return;
}
$constructClassMethodStmts = $constructClassMethod->stmts;
foreach ($constructClassMethod->getParams() as $param) {
$variable = $this->betterNodeFinder->findFirst($constructClassMethodStmts, function (Node $node) use (
$variable = $this->betterNodeFinder->findFirst((array) $constructClassMethod->stmts, function (Node $node) use (
$param
): bool {
return $this->nodeComparator->areNodesEqual($param->var, $node);

View File

@ -85,7 +85,7 @@ final class BetterNodeFinder
}
/**
* @template T of Node
* @template T of \PhpParser\Node
* @param array<class-string<T>> $types
* @return T|null
*/
@ -347,8 +347,8 @@ final class BetterNodeFinder
}
/**
* @param Node|Node[] $nodes
* @template T of Node
* @param Node|Node[] $nodes
* @param class-string<T> $type
* @return T|null
*/