Skip to content

Commit 352dbf1

Browse files
committed
Revert "use simple parser for defaultAnalysisParser, with native parser php 7.0"
This reverts commit b3d6c45.
1 parent b3d6c45 commit 352dbf1

File tree

5 files changed

+23
-58
lines changed

5 files changed

+23
-58
lines changed

config/phpstan/parser.neon

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# see original config.neon in phpstan.neon - https://github.com/phpstan/phpstan-src/blob/386eb913abb6ac05886c5642fd48b5d99db66a20/conf/config.neon#L1582
22
# this file overrides definitions from the config above
33
services:
4+
defaultAnalysisParser:
5+
factory: @pathRoutingParser
6+
arguments!: []
7+
8+
cachedRectorParser:
9+
class: PHPStan\Parser\CachedParser
10+
arguments:
11+
originalParser: @rectorParser
12+
cachedNodesByStringCountMax: %cache.nodesByStringCountMax%
13+
autowired: false
14+
415
pathRoutingParser:
516
class: PHPStan\Parser\PathRoutingParser
617
arguments:
@@ -9,40 +20,8 @@ services:
920
php8Parser: @php8Parser
1021
autowired: false
1122

12-
- Rector\PhpDocParser\PhpParser\SmartPhpParserFactory
13-
14-
nativeParser:
15-
class: PhpParser\Parser
16-
factory: ['@Rector\PhpDocParser\PhpParser\SmartPhpParserFactory', 'createNativePhpParser']
17-
autowired: no
18-
19-
phpstanParser:
20-
class: PhpParser\Parser
21-
factory: ['@Rector\PhpDocParser\PhpParser\SmartPhpParserFactory', 'createPHPStanParser']
22-
autowired: no
23-
24-
-
25-
class: PHPStan\Analyser\NodeScopeResolver
26-
arguments:
27-
parser: @nativeParser
28-
reflector: @nodeScopeResolverReflector
29-
polluteScopeWithLoopInitialAssignments: %polluteScopeWithLoopInitialAssignments%
30-
polluteScopeWithAlwaysIterableForeach: %polluteScopeWithAlwaysIterableForeach%
31-
polluteScopeWithBlock: %polluteScopeWithBlock%
32-
earlyTerminatingMethodCalls: %earlyTerminatingMethodCalls%
33-
earlyTerminatingFunctionCalls: %earlyTerminatingFunctionCalls%
34-
implicitThrows: %exceptions.implicitThrows%
35-
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
36-
universalObjectCratesClasses: %universalObjectCratesClasses%
37-
autowired: false
38-
39-
defaultAnalysisParser:
40-
factory: ['@Rector\PhpDocParser\PhpParser\SmartPhpParserFactory', 'createPHPStanParser']
41-
arguments!: []
42-
43-
cachedRectorParser:
44-
class: PHPStan\Parser\CachedParser
23+
rectorParser:
24+
class: PHPStan\Parser\RichParser
4525
arguments:
46-
originalParser: @phpstanParser
47-
cachedNodesByStringCountMax: %cache.nodesByStringCountMax%
48-
autowired: false
26+
parser: @currentPhpVersionPhpParser
27+
autowired: no

rules/Php74/Rector/ArrayDimFetch/CurlyToSquareBracketArrayStringRector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ private function isFollowedByCurlyBracket(File $file, ArrayDimFetch $arrayDimFet
7777
$oldTokens = $file->getOldTokens();
7878
$endTokenPost = $arrayDimFetch->getEndTokenPos();
7979

80-
if (isset($oldTokens[$endTokenPost]) && (string) $oldTokens[$endTokenPost] === '}') {
81-
return true;
80+
if (isset($oldTokens[$endTokenPost]) && $oldTokens[$endTokenPost] === '}') {
81+
$startTokenPost = $arrayDimFetch->getStartTokenPos();
82+
return ! (isset($oldTokens[$startTokenPost][1]) && $oldTokens[$startTokenPost][1] === '${');
8283
}
8384

8485
return false;

src/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Rector\Configuration\Option;
1717
use Rector\Configuration\Parameter\SimpleParameterProvider;
1818
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
19-
use Rector\PhpDocParser\PhpParser\SmartPhpParserFactory;
2019
use Symfony\Component\Console\Input\ArrayInput;
2120
use Symfony\Component\Console\Output\ConsoleOutput;
2221
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -89,8 +88,7 @@ public function createEmulativeLexer(): Lexer
8988
*/
9089
public function createPHPStanParser(): Parser
9190
{
92-
$smartPhpParserFactory = new SmartPhpParserFactory();
93-
return $smartPhpParserFactory->createSimpleParser();
91+
return $this->container->getService('currentPhpVersionRichParser');
9492
}
9593

9694
/**

src/PhpDocParser/PhpParser/SmartPhpParserFactory.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PhpParser\NodeVisitor\NameResolver;
88
use PhpParser\Parser;
99
use PhpParser\ParserFactory;
10-
use PhpParser\PhpVersion;
1110
use PHPStan\Parser\CachedParser;
1211
use PHPStan\Parser\SimpleParser;
1312
use PHPStan\Parser\VariadicFunctionsVisitor;
@@ -32,15 +31,14 @@ public function create(): SmartPhpParser
3231
return new SmartPhpParser($cachedParser);
3332
}
3433

35-
public function createNativePhpParser(): Parser
34+
private function createNativePhpParser(): Parser
3635
{
3736
$parserFactory = new ParserFactory();
38-
return $parserFactory->createForVersion(PhpVersion::fromString('7.0'));
37+
return $parserFactory->createForNewestSupportedVersion();
3938
}
4039

41-
public function createPHPStanParser(): CachedParser
40+
private function createPHPStanParser(Parser $parser): CachedParser
4241
{
43-
$parser = $this->createNativePhpParser();
4442
$nameResolver = new NameResolver();
4543
$variadicMethodsVisitor = new VariadicMethodsVisitor();
4644
$variadicFunctionsVisitor = new VariadicFunctionsVisitor();
@@ -49,14 +47,4 @@ public function createPHPStanParser(): CachedParser
4947

5048
return new CachedParser($simpleParser, 1024);
5149
}
52-
53-
public function createSimpleParser(): SimpleParser
54-
{
55-
$parser = $this->createNativePhpParser();
56-
$nameResolver = new NameResolver();
57-
$variadicMethodsVisitor = new VariadicMethodsVisitor();
58-
$variadicFunctionsVisitor = new VariadicFunctionsVisitor();
59-
60-
return new SimpleParser($parser, $nameResolver, $variadicMethodsVisitor, $variadicFunctionsVisitor);
61-
}
6250
}

src/PhpParser/Parser/SimplePhpParser.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PhpParser\NodeTraverser;
1111
use PhpParser\Parser;
1212
use PhpParser\ParserFactory;
13-
use PhpParser\PhpVersion;
1413
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\AssignedToNodeVisitor;
1514
use Throwable;
1615

@@ -23,7 +22,7 @@
2322
public function __construct()
2423
{
2524
$parserFactory = new ParserFactory();
26-
$this->phpParser = $parserFactory->createForVersion(PhpVersion::fromString('7.0'));
25+
$this->phpParser = $parserFactory->createForNewestSupportedVersion();
2726

2827
$this->nodeTraverser = new NodeTraverser();
2928
$this->nodeTraverser->addVisitor(new AssignedToNodeVisitor());

0 commit comments

Comments
 (0)