Skip to content

Commit 01406fb

Browse files
Bump to PHPStan 2.1.34 and fix compatible code (#7844)
* Bump to phpstan 2.1.34 * remove no longer exists visitor * use factory file * handle FiberScope * handle FiberScope * handle FiberScope * handle FiberScope * fix phpsta * cs fix * fix phpstan * [ci-review] Rector Rectify * fix getParentScope() * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 732278e commit 01406fb

File tree

7 files changed

+42
-11
lines changed

7 files changed

+42
-11
lines changed

build/target-repository/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"require": {
1111
"php": "^7.4|^8.0",
12-
"phpstan/phpstan": "^2.1.33"
12+
"phpstan/phpstan": "^2.1.34"
1313
},
1414
"autoload": {
1515
"files": [

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"nikic/php-parser": "^5.7",
2424
"ondram/ci-detector": "^4.2",
2525
"phpstan/phpdoc-parser": "^2.3",
26-
"phpstan/phpstan": "^2.1.33",
26+
"phpstan/phpstan": "^2.1.34",
2727
"react/event-loop": "^1.6",
2828
"react/promise": "^3.3",
2929
"react/socket": "^1.17",

phpstan.neon

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,29 @@ parameters:
438438
-
439439
identifier: symplify.noMissnamedDocTag
440440
path: rules/TypeDeclarationDocblocks/TypeResolver/ConstantArrayTypeGeneralizer.php
441+
442+
-
443+
identifier: typePerfect.narrowReturnObjectType
444+
path: src/PHPStan/ScopeFetcher.php
445+
446+
-
447+
identifier: varTag.nativeType
448+
path: src/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php
449+
450+
-
451+
identifier: argument.type
452+
paths:
453+
- rules/Privatization/TypeManipulator/TypeNormalizer.php
454+
- rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayMapRector.php
455+
- rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayMapRector.php
456+
- rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayReduceRector.php
457+
- rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayReduceRector.php
458+
- rules/TypeDeclarationDocblocks/Rector/Class_/AddVarArrayDocblockFromDimFetchAssignRector.php
459+
- src/NodeTypeResolver/PHPStan/Type/TypeFactory.php
460+
461+
-
462+
identifier: argument.templateType
463+
paths:
464+
- rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayMapRector.php
465+
- rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayReduceRector.php
466+
- src/NodeTypeResolver/PHPStan/Type/TypeFactory.php

rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rector\Php81\NodeManipulator;
66

7+
use PHPStan\Analyser\Fiber\FiberScope;
78
use PhpParser\Node\Arg;
89
use PhpParser\Node\Expr;
910
use PhpParser\Node\Expr\Cast\Int_ as CastInt_;
@@ -213,6 +214,10 @@ private function isAnErrorType(Expr $expr, Type $type, Scope $scope): bool
213214
}
214215

215216
$parentScope = $scope->getParentScope();
217+
if ($parentScope instanceof FiberScope) {
218+
$parentScope = $parentScope->toMutatingScope();
219+
}
220+
216221
if ($parentScope instanceof Scope) {
217222
return $parentScope->getType($expr) instanceof ErrorType;
218223
}

src/DependencyInjection/PHPStan/PHPStanContainerMemento.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use PHPStan\Parser\AnonymousClassVisitor;
1010
use PHPStan\Parser\ArrayMapArgVisitor;
1111
use PHPStan\Parser\RichParser;
12-
use PHPStan\Parser\VariadicFunctionsVisitor;
13-
use PHPStan\Parser\VariadicMethodsVisitor;
1412
use Rector\Util\Reflection\PrivatesAccessor;
1513

1614
/**
@@ -41,8 +39,6 @@ public static function removeRichVisitors(RichParser $richParser): void
4139
// remove all the rest, https://github.com/phpstan/phpstan-src/tree/1d86de8bb9371534983a8dbcd879e057d2ff028f/src/Parser
4240
$nodeVisitorsToKeep = [
4341
$container->findServiceNamesByType(AnonymousClassVisitor::class)[0] => true,
44-
$container->findServiceNamesByType(VariadicFunctionsVisitor::class)[0] => true,
45-
$container->findServiceNamesByType(VariadicMethodsVisitor::class)[0] => true,
4642
$container->findServiceNamesByType(ArrayMapArgVisitor::class)[0] => true,
4743
];
4844

src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rector\NodeTypeResolver\PHPStan\Scope;
66

7+
use PHPStan\Analyser\Fiber\FiberScope;
78
use Error;
89
use PhpParser\Node;
910
use PhpParser\Node\Arg;
@@ -158,6 +159,10 @@ public function processNodes(
158159
&$nodeCallback,
159160
$filePath,
160161
): void {
162+
if ($mutatingScope instanceof FiberScope) {
163+
$mutatingScope = $mutatingScope->toMutatingScope();
164+
}
165+
161166
// the class reflection is resolved AFTER entering to class node
162167
// so we need to get it from the first after this one
163168
if ($node instanceof Class_ || $node instanceof Interface_ || $node instanceof Enum_) {

src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
use PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
88
use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator;
9-
use PHPStan\Reflection\BetterReflection\SourceLocator\FileNodesFetcher;
109
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocatorFactory;
11-
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocator;
10+
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocatorRepository;
1211
use Rector\Contract\DependencyInjection\ResettableInterface;
1312
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
1413

@@ -30,8 +29,8 @@ final class DynamicSourceLocatorProvider implements ResettableInterface
3029
private ?AggregateSourceLocator $aggregateSourceLocator = null;
3130

3231
public function __construct(
33-
private readonly FileNodesFetcher $fileNodesFetcher,
34-
private readonly OptimizedDirectorySourceLocatorFactory $optimizedDirectorySourceLocatorFactory
32+
private readonly OptimizedDirectorySourceLocatorFactory $optimizedDirectorySourceLocatorFactory,
33+
private readonly OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository
3534
) {
3635
}
3736

@@ -68,7 +67,7 @@ public function provide(): SourceLocator
6867
$sourceLocators = [];
6968

7069
foreach ($this->filePaths as $file) {
71-
$sourceLocators[] = new OptimizedSingleFileSourceLocator($this->fileNodesFetcher, $file);
70+
$sourceLocators[] = $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($file);
7271
}
7372

7473
foreach ($this->directories as $directory) {

0 commit comments

Comments
 (0)