Skip to content

Commit ac0e705

Browse files
committed
remove docblock based type, as might be invalid
1 parent 3d0786d commit ac0e705

File tree

4 files changed

+12
-39
lines changed

4 files changed

+12
-39
lines changed

rules-tests/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector/Fixture/return_by_array_shape_type.php.inc

Lines changed: 0 additions & 33 deletions
This file was deleted.

rules/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PhpParser\Node\Expr\Instanceof_;
1313
use PhpParser\Node\Expr\Variable;
1414
use PhpParser\Node\Identifier;
15+
use PhpParser\Node\Scalar\String_;
1516
use PHPStan\Type\ArrayType;
1617
use Rector\PhpParser\Node\BetterNodeFinder;
1718
use Rector\Rector\AbstractRector;
@@ -148,7 +149,8 @@ private function resolveDimFetchVariableNames(Closure|ArrowFunction $closureExpr
148149
if ($arrayDimFetch->var instanceof Variable) {
149150
$type = $this->nodeTypeResolver->getNativeType($arrayDimFetch->var);
150151

151-
if ($type->isString()->yes()) {
152+
// skip string values
153+
if (! $arrayDimFetch->dim instanceof String_ && ($type->isString()->yes() || $type->isString()->maybe())) {
152154
continue;
153155
}
154156

src/DependencyInjection/PHPStan/PHPStanContainerMemento.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use PHPStan\DependencyInjection\Nette\NetteContainer;
99
use PHPStan\Parser\AnonymousClassVisitor;
1010
use PHPStan\Parser\RichParser;
11+
use PHPStan\Parser\VariadicFunctionsVisitor;
12+
use PHPStan\Parser\VariadicMethodsVisitor;
1113
use Rector\Util\Reflection\PrivatesAccessor;
1214

1315
/**
@@ -34,12 +36,16 @@ public static function removeRichVisitors(RichParser $richParser): void
3436
// get tags property
3537
$tags = $privatesAccessor->getPrivateProperty($deeperContainer, 'tags');
3638

37-
// keep only the anonymous class visitor
39+
// keep visitors that are useful
3840
// remove all the rest, https://github.com/phpstan/phpstan-src/tree/1d86de8bb9371534983a8dbcd879e057d2ff028f/src/Parser
39-
$tags[RichParser::VISITOR_SERVICE_TAG] = [
41+
$nodeVisitorsToKeep = [
4042
$container->findServiceNamesByType(AnonymousClassVisitor::class)[0] => true,
43+
$container->findServiceNamesByType(VariadicFunctionsVisitor::class)[0] => true,
44+
$container->findServiceNamesByType(VariadicMethodsVisitor::class)[0] => true,
4145
];
4246

47+
$tags[RichParser::VISITOR_SERVICE_TAG] = $nodeVisitorsToKeep;
48+
4349
$privatesAccessor->setPrivateProperty($deeperContainer, 'tags', $tags);
4450
}
4551
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
<?php
22

3-
namespace Rector\Tests\PhpParser\Printer\Fixture;
4-
5-
$result = array_map(array: [1, 2, 3], callback: fn(int $value) => $value);
3+
$result = \array_map(array: [1, 2, 3], callback: fn(int $value) => $value);

0 commit comments

Comments
 (0)