Skip to content

Commit

Permalink
Revert "use simple parser for defaultAnalysisParser, with native pars…
Browse files Browse the repository at this point in the history
…er php 7.0"

This reverts commit b3d6c45.
  • Loading branch information
samsonasik committed Nov 17, 2024
1 parent b3d6c45 commit 352dbf1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 58 deletions.
51 changes: 15 additions & 36 deletions config/phpstan/parser.neon
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,8 +88,7 @@ public function createEmulativeLexer(): Lexer
*/
public function createPHPStanParser(): Parser
{
$smartPhpParserFactory = new SmartPhpParserFactory();
return $smartPhpParserFactory->createSimpleParser();
return $this->container->getService('currentPhpVersionRichParser');
}

/**
Expand Down
18 changes: 3 additions & 15 deletions src/PhpDocParser/PhpParser/SmartPhpParserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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);
}
}
3 changes: 1 addition & 2 deletions src/PhpParser/Parser/SimplePhpParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
Expand Down

0 comments on commit 352dbf1

Please sign in to comment.