Skip to content

Commit d916aa6

Browse files
authored
Merge pull request #10567 from edsrzf/php-parser-5
Update nikic/php-parser to 5.0
2 parents bf57d59 + 9577ff5 commit d916aa6

File tree

64 files changed

+310
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+310
-299
lines changed

composer.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,12 @@
3333
"felixfbecker/language-server-protocol": "^1.5.2",
3434
"fidry/cpu-core-counter": "^0.4.1 || ^0.5.1 || ^1.0.0",
3535
"netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0",
36-
"nikic/php-parser": "^4.16",
36+
"nikic/php-parser": "^5.0.0",
3737
"sebastian/diff": "^4.0 || ^5.0",
3838
"spatie/array-to-xml": "^2.17.0 || ^3.0",
3939
"symfony/console": "^4.1.6 || ^5.0 || ^6.0 || ^7.0",
4040
"symfony/filesystem": "^5.4 || ^6.0 || ^7.0"
4141
},
42-
"conflict": {
43-
"nikic/php-parser": "4.17.0"
44-
},
4542
"provide": {
4643
"psalm/psalm": "self.version"
4744
},

examples/plugins/SafeArrayKeyChecker.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Psalm\Example\Plugin;
44

5-
use PhpParser\Node\Expr\ArrayItem;
5+
use PhpParser\Node\ArrayItem;
66
use Psalm\Internal\Analyzer\StatementsAnalyzer;
77
use Psalm\Plugin\EventHandler\Event\AddRemoveTaintsEvent;
88
use Psalm\Plugin\EventHandler\RemoveTaintsInterface;

psalm-baseline.xml

-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<files psalm-version="dev-master@950293c6e74c6e9db842f537c5722755b1594313">
3-
<file src="vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrowFunction.php">
4-
<PossiblyUndefinedStringArrayOffset>
5-
<code><![CDATA[$subNodes['expr']]]></code>
6-
</PossiblyUndefinedStringArrayOffset>
7-
</file>
83
<file src="examples/TemplateChecker.php">
94
<PossiblyUndefinedIntArrayOffset>
105
<code><![CDATA[$comment_block->tags['variablesfrom'][0]]]></code>
@@ -2351,9 +2346,4 @@
23512346
<code>$return_type</code>
23522347
</RiskyTruthyFalsyComparison>
23532348
</file>
2354-
<file src="vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrowFunction.php">
2355-
<PossiblyUndefinedStringArrayOffset>
2356-
<code><![CDATA[$subNodes['expr']]]></code>
2357-
</PossiblyUndefinedStringArrayOffset>
2358-
</file>
23592349
</files>

psalm.xml.dist

+21
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,31 @@
144144
</errorLevel>
145145
</PropertyTypeCoercion>
146146

147+
<InvalidArrayOffset>
148+
<errorLevel type="suppress">
149+
<file name="vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/Class_.php" />
150+
<file name="vendor/nikic/php-parser/lib/PhpParser/Node/Stmt/ClassMethod.php" />
151+
</errorLevel>
152+
</InvalidArrayOffset>
153+
154+
<InvalidPropertyAssignmentValue>
155+
<errorLevel type="suppress">
156+
<file name="vendor/nikic/php-parser/lib/PhpParser/Node/MatchArm.php" />
157+
</errorLevel>
158+
</InvalidPropertyAssignmentValue>
159+
147160
<MixedAssignment>
148161
<errorLevel type="suppress">
149162
<directory name="vendor/nikic/php-parser" />
150163
</errorLevel>
151164
</MixedAssignment>
165+
166+
<PropertyNotSetInConstructor>
167+
<errorLevel type="suppress">
168+
<referencedProperty name="PhpParser\Node\Const_::$namespacedName" />
169+
<referencedProperty name="PhpParser\Node\Stmt\ClassLike::$namespacedName" />
170+
<referencedProperty name="PhpParser\Node\Stmt\Function_::$namespacedName" />
171+
</errorLevel>
172+
</PropertyNotSetInConstructor>
152173
</issueHandlers>
153174
</psalm>

src/Psalm/CodeLocation/ParseErrorLocation.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public function __construct(
1919
string $file_path,
2020
string $file_name,
2121
) {
22-
/** @psalm-suppress PossiblyUndefinedStringArrayOffset, ImpureMethodCall */
22+
/** @psalm-suppress PossiblyUndefinedStringArrayOffset */
2323
$this->file_start = (int)$error->getAttributes()['startFilePos'];
24-
/** @psalm-suppress PossiblyUndefinedStringArrayOffset, ImpureMethodCall */
24+
/** @psalm-suppress PossiblyUndefinedStringArrayOffset */
2525
$this->file_end = (int)$error->getAttributes()['endFilePos'];
2626
$this->raw_file_start = $this->file_start;
2727
$this->raw_file_end = $this->file_end;

src/Psalm/Internal/Analyzer/ClassAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ static function (FunctionLikeParameter $param): PhpParser\Node\Arg {
11951195
$fake_stmt = new VirtualClassMethod(
11961196
new VirtualIdentifier('__construct'),
11971197
[
1198-
'flags' => PhpParser\Node\Stmt\Class_::MODIFIER_PUBLIC,
1198+
'flags' => PhpParser\Modifiers::PUBLIC,
11991199
'params' => $fake_constructor_params,
12001200
'stmts' => $fake_constructor_stmts,
12011201
],

src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeCollector.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static function getReturnTypes(
5454
$yield_types = array_merge($yield_types, self::getYieldTypeFromExpression($stmt->expr, $nodes));
5555
} elseif ($stmt->expr instanceof PhpParser\Node\Scalar\String_) {
5656
$return_types[] = Type::getString();
57-
} elseif ($stmt->expr instanceof PhpParser\Node\Scalar\LNumber) {
57+
} elseif ($stmt->expr instanceof PhpParser\Node\Scalar\Int_) {
5858
$return_types[] = Type::getInt();
5959
} elseif ($stmt->expr instanceof PhpParser\Node\Expr\ConstFetch) {
6060
if ((string)$stmt->expr->name === 'true') {
@@ -77,14 +77,9 @@ public static function getReturnTypes(
7777
break;
7878
}
7979

80-
if ($stmt instanceof PhpParser\Node\Stmt\Throw_) {
81-
$return_types[] = Type::getNever();
82-
83-
break;
84-
}
85-
8680
if ($stmt instanceof PhpParser\Node\Stmt\Expression) {
87-
if ($stmt->expr instanceof PhpParser\Node\Expr\Exit_) {
81+
if ($stmt->expr instanceof PhpParser\Node\Expr\Exit_
82+
|| $stmt->expr instanceof PhpParser\Node\Expr\Throw_) {
8883
$return_types[] = Type::getNever();
8984

9085
break;

src/Psalm/Internal/Analyzer/ProjectAnalyzer.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1186,8 +1186,7 @@ public function setPhpVersion(string $version, string $source): void
11861186
$analysis_php_version_id = $php_major_version * 10_000 + $php_minor_version * 100;
11871187

11881188
if ($this->codebase->analysis_php_version_id !== $analysis_php_version_id) {
1189-
// reset lexer and parser when php version changes
1190-
StatementsProvider::clearLexer();
1189+
// reset parser when php version changes
11911190
StatementsProvider::clearParser();
11921191
}
11931192

src/Psalm/Internal/Analyzer/ScopeAnalyzer.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ public static function getControlActions(
5050

5151
foreach ($stmts as $stmt) {
5252
if ($stmt instanceof PhpParser\Node\Stmt\Return_ ||
53-
$stmt instanceof PhpParser\Node\Stmt\Throw_ ||
54-
($stmt instanceof PhpParser\Node\Stmt\Expression && $stmt->expr instanceof PhpParser\Node\Expr\Exit_)
53+
($stmt instanceof PhpParser\Node\Stmt\Expression
54+
&& ($stmt->expr instanceof PhpParser\Node\Expr\Exit_
55+
|| $stmt->expr instanceof PhpParser\Node\Expr\Throw_))
5556
) {
5657
if (!$return_is_exit && $stmt instanceof PhpParser\Node\Stmt\Return_) {
5758
$stmt_return_type = null;
@@ -85,7 +86,7 @@ public static function getControlActions(
8586
if ($stmt instanceof PhpParser\Node\Stmt\Continue_) {
8687
$count = !$stmt->num
8788
? 1
88-
: ($stmt->num instanceof PhpParser\Node\Scalar\LNumber ? $stmt->num->value : null);
89+
: ($stmt->num instanceof PhpParser\Node\Scalar\Int_ ? $stmt->num->value : null);
8990

9091
if ($break_types && $count !== null && count($break_types) >= $count) {
9192
/** @psalm-suppress InvalidArrayOffset Some int-range improvements are needed */
@@ -102,7 +103,7 @@ public static function getControlActions(
102103
if ($stmt instanceof PhpParser\Node\Stmt\Break_) {
103104
$count = !$stmt->num
104105
? 1
105-
: ($stmt->num instanceof PhpParser\Node\Scalar\LNumber ? $stmt->num->value : null);
106+
: ($stmt->num instanceof PhpParser\Node\Scalar\Int_ ? $stmt->num->value : null);
106107

107108
if ($break_types && $count !== null && count($break_types) >= $count) {
108109
/** @psalm-suppress InvalidArrayOffset Some int-range improvements are needed */
@@ -408,9 +409,9 @@ public static function onlyThrowsOrExits(NodeTypeProvider $type_provider, array
408409
for ($i = count($stmts) - 1; $i >= 0; --$i) {
409410
$stmt = $stmts[$i];
410411

411-
if ($stmt instanceof PhpParser\Node\Stmt\Throw_
412-
|| ($stmt instanceof PhpParser\Node\Stmt\Expression
413-
&& $stmt->expr instanceof PhpParser\Node\Expr\Exit_)
412+
if ($stmt instanceof PhpParser\Node\Stmt\Expression
413+
&& ($stmt->expr instanceof PhpParser\Node\Expr\Exit_
414+
|| $stmt->expr instanceof PhpParser\Node\Expr\Throw_)
414415
) {
415416
return true;
416417
}
@@ -438,7 +439,7 @@ public static function onlyThrows(array $stmts): bool
438439
}
439440

440441
foreach ($stmts as $stmt) {
441-
if ($stmt instanceof PhpParser\Node\Stmt\Throw_) {
442+
if ($stmt instanceof PhpParser\Node\Stmt\Expression && $stmt->expr instanceof PhpParser\Node\Expr\Throw_) {
442443
return true;
443444
}
444445
}

src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
use Psalm\Node\Expr\BinaryOp\VirtualEqual;
2727
use Psalm\Node\Expr\BinaryOp\VirtualIdentical;
2828
use Psalm\Node\Expr\VirtualArray;
29-
use Psalm\Node\Expr\VirtualArrayItem;
3029
use Psalm\Node\Expr\VirtualBooleanNot;
3130
use Psalm\Node\Expr\VirtualConstFetch;
3231
use Psalm\Node\Expr\VirtualFuncCall;
3332
use Psalm\Node\Expr\VirtualVariable;
3433
use Psalm\Node\Name\VirtualFullyQualified;
35-
use Psalm\Node\Scalar\VirtualLNumber;
34+
use Psalm\Node\Scalar\VirtualInt;
3635
use Psalm\Node\Stmt\VirtualIf;
3736
use Psalm\Node\VirtualArg;
37+
use Psalm\Node\VirtualArrayItem;
3838
use Psalm\Node\VirtualName;
3939
use Psalm\Type;
4040
use Psalm\Type\Atomic\TDependentGetClass;
@@ -249,8 +249,8 @@ public static function analyze(
249249
$case_equality_expr = new VirtualFuncCall(
250250
new VirtualFullyQualified(['rand']),
251251
[
252-
new VirtualArg(new VirtualLNumber(0)),
253-
new VirtualArg(new VirtualLNumber(1)),
252+
new VirtualArg(new VirtualInt(0)),
253+
new VirtualArg(new VirtualInt(1)),
254254
],
255255
$case->getAttributes(),
256256
);
@@ -294,8 +294,8 @@ public static function analyze(
294294
$case_or_default_equality_expr = new VirtualFuncCall(
295295
new VirtualFullyQualified(['rand']),
296296
[
297-
new VirtualArg(new VirtualLNumber(0)),
298-
new VirtualArg(new VirtualLNumber(1)),
297+
new VirtualArg(new VirtualInt(0)),
298+
new VirtualArg(new VirtualInt(1)),
299299
],
300300
$case->getAttributes(),
301301
);
@@ -690,8 +690,8 @@ private static function simplifyCaseEqualityExpression(
690690
}
691691

692692
/**
693-
* @param array<PhpParser\Node\Expr\ArrayItem> $in_array_values
694-
* @return ?array<PhpParser\Node\Expr\ArrayItem>
693+
* @param array<PhpParser\Node\ArrayItem> $in_array_values
694+
* @return ?array<PhpParser\Node\ArrayItem>
695695
*/
696696
private static function getOptionsFromNestedOr(
697697
PhpParser\Node\Expr $case_equality_expr,

src/Psalm/Internal/Analyzer/Statements/BreakAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function analyze(
2929
if ($loop_scope) {
3030
if ($context->break_types
3131
&& end($context->break_types) === 'switch'
32-
&& (!$stmt->num instanceof PhpParser\Node\Scalar\LNumber || $stmt->num->value < 2)
32+
&& (!$stmt->num instanceof PhpParser\Node\Scalar\Int_ || $stmt->num->value < 2)
3333
) {
3434
$loop_scope->final_actions[] = ScopeAnalyzer::ACTION_LEAVE_SWITCH;
3535
} else {

src/Psalm/Internal/Analyzer/Statements/ContinueAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function analyze(
2525
PhpParser\Node\Stmt\Continue_ $stmt,
2626
Context $context,
2727
): void {
28-
$count = $stmt->num instanceof PhpParser\Node\Scalar\LNumber? $stmt->num->value : 1;
28+
$count = $stmt->num instanceof PhpParser\Node\Scalar\Int_? $stmt->num->value : 1;
2929

3030
$loop_scope = $context->loop_scope;
3131

src/Psalm/Internal/Analyzer/Statements/Expression/ArrayAnalyzer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ private static function analyzeArrayItem(
242242
StatementsAnalyzer $statements_analyzer,
243243
Context $context,
244244
ArrayCreationInfo $array_creation_info,
245-
PhpParser\Node\Expr\ArrayItem $item,
245+
PhpParser\Node\ArrayItem $item,
246246
Codebase $codebase,
247247
): void {
248248
if ($item->unpack) {
@@ -519,7 +519,7 @@ private static function analyzeArrayItem(
519519
private static function handleUnpackedArray(
520520
StatementsAnalyzer $statements_analyzer,
521521
ArrayCreationInfo $array_creation_info,
522-
PhpParser\Node\Expr\ArrayItem $item,
522+
PhpParser\Node\ArrayItem $item,
523523
Union $unpacked_array_type,
524524
Codebase $codebase,
525525
): void {

0 commit comments

Comments
 (0)