diff --git a/config/phpstan/parser.neon b/config/phpstan/parser.neon index ee34c603214..3b0f385dce2 100644 --- a/config/phpstan/parser.neon +++ b/config/phpstan/parser.neon @@ -1,6 +1,17 @@ # see original config.neon in phpstan.neon - https://github.com/phpstan/phpstan-src/blob/386eb913abb6ac05886c5642fd48b5d99db66a20/conf/config.neon#L1582 # this file overrides definitions from the config above services: + defaultAnalysisParser: + factory: @pathRoutingParser + arguments!: [] + + cachedRectorParser: + class: PHPStan\Parser\CachedParser + arguments: + originalParser: @rectorParser + cachedNodesByStringCountMax: %cache.nodesByStringCountMax% + autowired: false + pathRoutingParser: class: PHPStan\Parser\PathRoutingParser arguments: @@ -9,40 +20,8 @@ services: php8Parser: @php8Parser autowired: false - - Rector\PhpDocParser\PhpParser\SmartPhpParserFactory - - nativeParser: - class: PhpParser\Parser - factory: ['@Rector\PhpDocParser\PhpParser\SmartPhpParserFactory', 'createNativePhpParser'] - autowired: no - - phpstanParser: - class: PhpParser\Parser - factory: ['@Rector\PhpDocParser\PhpParser\SmartPhpParserFactory', 'createPHPStanParser'] - autowired: no - - - - class: PHPStan\Analyser\NodeScopeResolver - arguments: - parser: @nativeParser - reflector: @nodeScopeResolverReflector - polluteScopeWithLoopInitialAssignments: %polluteScopeWithLoopInitialAssignments% - polluteScopeWithAlwaysIterableForeach: %polluteScopeWithAlwaysIterableForeach% - polluteScopeWithBlock: %polluteScopeWithBlock% - earlyTerminatingMethodCalls: %earlyTerminatingMethodCalls% - earlyTerminatingFunctionCalls: %earlyTerminatingFunctionCalls% - implicitThrows: %exceptions.implicitThrows% - treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain% - universalObjectCratesClasses: %universalObjectCratesClasses% - autowired: false - - defaultAnalysisParser: - factory: ['@Rector\PhpDocParser\PhpParser\SmartPhpParserFactory', 'createPHPStanParser'] - arguments!: [] - - cachedRectorParser: - class: PHPStan\Parser\CachedParser + rectorParser: + class: PHPStan\Parser\RichParser arguments: - originalParser: @phpstanParser - cachedNodesByStringCountMax: %cache.nodesByStringCountMax% - autowired: false + parser: @currentPhpVersionPhpParser + autowired: no diff --git a/rules/Php74/Rector/ArrayDimFetch/CurlyToSquareBracketArrayStringRector.php b/rules/Php74/Rector/ArrayDimFetch/CurlyToSquareBracketArrayStringRector.php index debb9dcd51b..848d9638c31 100644 --- a/rules/Php74/Rector/ArrayDimFetch/CurlyToSquareBracketArrayStringRector.php +++ b/rules/Php74/Rector/ArrayDimFetch/CurlyToSquareBracketArrayStringRector.php @@ -77,8 +77,9 @@ private function isFollowedByCurlyBracket(File $file, ArrayDimFetch $arrayDimFet $oldTokens = $file->getOldTokens(); $endTokenPost = $arrayDimFetch->getEndTokenPos(); - if (isset($oldTokens[$endTokenPost]) && (string) $oldTokens[$endTokenPost] === '}') { - return true; + if (isset($oldTokens[$endTokenPost]) && $oldTokens[$endTokenPost] === '}') { + $startTokenPost = $arrayDimFetch->getStartTokenPos(); + return ! (isset($oldTokens[$startTokenPost][1]) && $oldTokens[$startTokenPost][1] === '${'); } return false; diff --git a/src/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php b/src/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php index 5f9a1f4dfc1..7f4b450d126 100644 --- a/src/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php +++ b/src/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php @@ -16,7 +16,6 @@ use Rector\Configuration\Option; use Rector\Configuration\Parameter\SimpleParameterProvider; use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider; -use Rector\PhpDocParser\PhpParser\SmartPhpParserFactory; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Style\SymfonyStyle; @@ -89,8 +88,7 @@ public function createEmulativeLexer(): Lexer */ public function createPHPStanParser(): Parser { - $smartPhpParserFactory = new SmartPhpParserFactory(); - return $smartPhpParserFactory->createSimpleParser(); + return $this->container->getService('currentPhpVersionRichParser'); } /** diff --git a/src/PhpDocParser/PhpParser/SmartPhpParserFactory.php b/src/PhpDocParser/PhpParser/SmartPhpParserFactory.php index 4d5479f33ac..b02e3aef6e6 100644 --- a/src/PhpDocParser/PhpParser/SmartPhpParserFactory.php +++ b/src/PhpDocParser/PhpParser/SmartPhpParserFactory.php @@ -7,7 +7,6 @@ use PhpParser\NodeVisitor\NameResolver; use PhpParser\Parser; use PhpParser\ParserFactory; -use PhpParser\PhpVersion; use PHPStan\Parser\CachedParser; use PHPStan\Parser\SimpleParser; use PHPStan\Parser\VariadicFunctionsVisitor; @@ -32,15 +31,14 @@ public function create(): SmartPhpParser return new SmartPhpParser($cachedParser); } - public function createNativePhpParser(): Parser + private function createNativePhpParser(): Parser { $parserFactory = new ParserFactory(); - return $parserFactory->createForVersion(PhpVersion::fromString('7.0')); + return $parserFactory->createForNewestSupportedVersion(); } - public function createPHPStanParser(): CachedParser + private function createPHPStanParser(Parser $parser): CachedParser { - $parser = $this->createNativePhpParser(); $nameResolver = new NameResolver(); $variadicMethodsVisitor = new VariadicMethodsVisitor(); $variadicFunctionsVisitor = new VariadicFunctionsVisitor(); @@ -49,14 +47,4 @@ public function createPHPStanParser(): CachedParser return new CachedParser($simpleParser, 1024); } - - public function createSimpleParser(): SimpleParser - { - $parser = $this->createNativePhpParser(); - $nameResolver = new NameResolver(); - $variadicMethodsVisitor = new VariadicMethodsVisitor(); - $variadicFunctionsVisitor = new VariadicFunctionsVisitor(); - - return new SimpleParser($parser, $nameResolver, $variadicMethodsVisitor, $variadicFunctionsVisitor); - } } diff --git a/src/PhpParser/Parser/SimplePhpParser.php b/src/PhpParser/Parser/SimplePhpParser.php index 4f0803ebab5..8b51c09a77c 100644 --- a/src/PhpParser/Parser/SimplePhpParser.php +++ b/src/PhpParser/Parser/SimplePhpParser.php @@ -10,7 +10,6 @@ use PhpParser\NodeTraverser; use PhpParser\Parser; use PhpParser\ParserFactory; -use PhpParser\PhpVersion; use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\AssignedToNodeVisitor; use Throwable; @@ -23,7 +22,7 @@ public function __construct() { $parserFactory = new ParserFactory(); - $this->phpParser = $parserFactory->createForVersion(PhpVersion::fromString('7.0')); + $this->phpParser = $parserFactory->createForNewestSupportedVersion(); $this->nodeTraverser = new NodeTraverser(); $this->nodeTraverser->addVisitor(new AssignedToNodeVisitor());