Skip to content

Commit 41ac212

Browse files
committed
Remove RequireParenthesesForNestedTernaryRule
1 parent f956c6d commit 41ac212

File tree

11 files changed

+3
-384
lines changed

11 files changed

+3
-384
lines changed

conf/config.level0.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ rules:
5454
- PHPStan\Rules\Properties\AccessPropertiesInAssignRule
5555
- PHPStan\Rules\Properties\AccessStaticPropertiesInAssignRule
5656
- PHPStan\Rules\Properties\PropertyAttributesRule
57-
- PHPStan\Rules\Ternary\RequireParenthesesForNestedTernaryRule
5857
- PHPStan\Rules\Variables\UnsetRule
5958

6059
services:

conf/config.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,6 @@ services:
516516
-
517517
class: PHPStan\Parser\FunctionCallStatementFinder
518518

519-
-
520-
class: PHPStan\Parser\NodeChildrenVisitor
521-
522519
-
523520
class: PHPStan\Process\CpuCoreCounter
524521

@@ -1177,7 +1174,6 @@ services:
11771174
class: PHPStan\Parser\RichParser
11781175
arguments:
11791176
parser: @currentPhpVersionPhpParser
1180-
lexer: @currentPhpVersionLexer
11811177
autowired: no
11821178

11831179
currentPhpVersionSimpleParser:

src/Parser/NodeChildrenVisitor.php

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

src/Parser/NodeTokensVisitor.php

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

src/Parser/RichParser.php

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,34 @@
33
namespace PHPStan\Parser;
44

55
use PhpParser\ErrorHandler\Collecting;
6-
use PhpParser\Lexer;
76
use PhpParser\NodeTraverser;
87
use PhpParser\NodeVisitor\NameResolver;
98
use PhpParser\NodeVisitor\NodeConnectingVisitor;
109
use PHPStan\File\FileReader;
1110
use PHPStan\NodeVisitor\StatementOrderVisitor;
12-
use PHPStan\Php\PhpVersion;
1311

1412
class RichParser implements Parser
1513
{
1614

1715
private \PhpParser\Parser $parser;
1816

19-
private Lexer $lexer;
20-
2117
private NameResolver $nameResolver;
2218

2319
private NodeConnectingVisitor $nodeConnectingVisitor;
2420

2521
private StatementOrderVisitor $statementOrderVisitor;
2622

27-
private NodeChildrenVisitor $nodeChildrenVisitor;
28-
29-
private PhpVersion $phpVersion;
30-
3123
public function __construct(
3224
\PhpParser\Parser $parser,
33-
Lexer $lexer,
3425
NameResolver $nameResolver,
3526
NodeConnectingVisitor $nodeConnectingVisitor,
36-
StatementOrderVisitor $statementOrderVisitor,
37-
NodeChildrenVisitor $nodeChildrenVisitor,
38-
PhpVersion $phpVersion
27+
StatementOrderVisitor $statementOrderVisitor
3928
)
4029
{
4130
$this->parser = $parser;
42-
$this->lexer = $lexer;
4331
$this->nameResolver = $nameResolver;
4432
$this->nodeConnectingVisitor = $nodeConnectingVisitor;
4533
$this->statementOrderVisitor = $statementOrderVisitor;
46-
$this->nodeChildrenVisitor = $nodeChildrenVisitor;
47-
$this->phpVersion = $phpVersion;
4834
}
4935

5036
/**
@@ -68,7 +54,6 @@ public function parseString(string $sourceCode): array
6854
{
6955
$errorHandler = new Collecting();
7056
$nodes = $this->parser->parse($sourceCode, $errorHandler);
71-
$tokens = $this->lexer->getTokens();
7257
if ($errorHandler->hasErrors()) {
7358
throw new \PHPStan\Parser\ParserErrorsException($errorHandler->getErrors(), null);
7459
}
@@ -81,22 +66,8 @@ public function parseString(string $sourceCode): array
8166
$nodeTraverser->addVisitor($this->nodeConnectingVisitor);
8267
$nodeTraverser->addVisitor($this->statementOrderVisitor);
8368

84-
if ($this->phpVersion->requiresParenthesesForNestedTernaries()) {
85-
$nodeTraverser->addVisitor($this->nodeChildrenVisitor);
86-
}
87-
88-
/** @var array<\PhpParser\Node\Stmt> */
89-
$nodes = $nodeTraverser->traverse($nodes);
90-
91-
if (!$this->phpVersion->requiresParenthesesForNestedTernaries()) {
92-
return $nodes;
93-
}
94-
95-
$tokensTraverser = new NodeTraverser();
96-
$tokensTraverser->addVisitor(new NodeTokensVisitor($tokens));
97-
9869
/** @var array<\PhpParser\Node\Stmt> */
99-
return $tokensTraverser->traverse($nodes);
70+
return $nodeTraverser->traverse($nodes);
10071
}
10172

10273
}

src/Php/PhpVersion.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ public function supportsLessOverridenParametersWithVariadic(): bool
5656
return $this->versionId >= 80000;
5757
}
5858

59-
public function requiresParenthesesForNestedTernaries(): bool
60-
{
61-
return $this->versionId >= 80000;
62-
}
63-
6459
public function supportsThrowExpression(): bool
6560
{
6661
return $this->versionId >= 80000;

src/Rules/Ternary/RequireParenthesesForNestedTernaryRule.php

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

tests/PHPStan/Analyser/AnalyserTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPStan\Dependency\ExportedNodeResolver;
1111
use PHPStan\File\RelativePathHelper;
1212
use PHPStan\NodeVisitor\StatementOrderVisitor;
13-
use PHPStan\Parser\NodeChildrenVisitor;
1413
use PHPStan\Parser\RichParser;
1514
use PHPStan\Php\PhpVersion;
1615
use PHPStan\PhpDoc\PhpDocInheritanceResolver;
@@ -523,12 +522,9 @@ private function createAnalyser(bool $reportUnmatchedIgnoredErrors): \PHPStan\An
523522
$nodeScopeResolver,
524523
new RichParser(
525524
new \PhpParser\Parser\Php7($lexer),
526-
$lexer,
527525
new \PhpParser\NodeVisitor\NameResolver(),
528526
new NodeConnectingVisitor(),
529-
new StatementOrderVisitor(),
530-
new NodeChildrenVisitor(),
531-
self::getContainer()->getByType(PhpVersion::class)
527+
new StatementOrderVisitor()
532528
),
533529
new DependencyResolver($fileHelper, $broker, new ExportedNodeResolver($fileTypeMapper, $printer)),
534530
$reportUnmatchedIgnoredErrors

0 commit comments

Comments
 (0)