Skip to content

Commit 8323e93

Browse files
authored
Bump PHPStan to 2.3.4 and phpdoc-parser to 2.4 (#8883)
* Bump PHPStan to 2.3.4 and phpdoc-parser to 2.4 Type::toPhpDocNode() now returns FullyQualifiedNameNode for class names, and GenericTypeNode::$type can be a NameNode: - import and rename FullyQualifiedNameNode in docblocks like a written \Foo\Bar - keep Rector's shortened, aliased and non-existing object types printed as written - check for IdentifierTypeNode before reading the generic type name Amp-Thread-ID: https://ampcode.com/threads/T-01a179f2-995f-7745-8d8c-4c174ba5c0ce * Bump PHPStan in downgraded composer.json to 2.3.4 Amp-Thread-ID: https://ampcode.com/threads/T-01a179f2-995f-7745-8d8c-4c174ba5c0ce * Regenerate preload files for phpdoc-parser 2.4 name nodes Amp-Thread-ID: https://ampcode.com/threads/T-01a17930-0285-73c5-a957-4325c77aa1b2
1 parent 62e0fcc commit 8323e93

14 files changed

Lines changed: 74 additions & 7 deletions

File tree

‎build/build-preload.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ function isPHPStanTestPreloaded(): bool
119119
'ConstExprNode.php',
120120
'PhpDocTagValueNode.php',
121121
'TypeNode.php',
122+
'NameNode.php',
123+
'NameNodeTrait.php',
122124
];
123125

124126
/**

‎build/target-repository/composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"require": {
1111
"php": "^7.4|^8.0",
12-
"phpstan/phpstan": "^2.3.3"
12+
"phpstan/phpstan": "^2.3.4"
1313
},
1414
"autoload": {
1515
"files": [

‎composer.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"nette/utils": "^4.1.5",
2323
"nikic/php-parser": "^5.9",
2424
"ondram/ci-detector": "^4.2",
25-
"phpstan/phpdoc-parser": "^2.3.8",
26-
"phpstan/phpstan": "^2.3.3",
25+
"phpstan/phpdoc-parser": "^2.4",
26+
"phpstan/phpstan": "^2.3.4",
2727
"react/child-process": "^0.6.5",
2828
"react/event-loop": "^1.6",
2929
"react/socket": "^1.17",

‎preload-split-package.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ function isPHPStanTestPreloaded(): bool
301301
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprNode.php';
302302
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/PhpDocTagValueNode.php';
303303
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/TypeNode.php';
304+
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/NameNode.php';
305+
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/NameNodeTrait.php';
304306
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/AbstractNodeVisitor.php';
305307
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Attribute.php';
306308
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprArrayItemNode.php';
@@ -364,6 +366,7 @@ function isPHPStanTestPreloaded(): bool
364366
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/ConditionalTypeForParameterNode.php';
365367
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/ConditionalTypeNode.php';
366368
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/ConstTypeNode.php';
369+
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/FullyQualifiedNameNode.php';
367370
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/GenericTypeNode.php';
368371
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/IdentifierTypeNode.php';
369372
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/IntersectionTypeNode.php';
@@ -372,6 +375,7 @@ function isPHPStanTestPreloaded(): bool
372375
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/ObjectShapeItemNode.php';
373376
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/ObjectShapeNode.php';
374377
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/OffsetAccessTypeNode.php';
378+
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/RelativeNameNode.php';
375379
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/ThisTypeNode.php';
376380
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Ast/Type/UnionTypeNode.php';
377381
require_once __DIR__ . '/../../../vendor/phpstan/phpdoc-parser/src/Parser/ConstExprParser.php';

‎preload.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ function isPHPStanTestPreloaded(): bool
301301
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprNode.php';
302302
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/PhpDocTagValueNode.php';
303303
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/TypeNode.php';
304+
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/NameNode.php';
305+
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/NameNodeTrait.php';
304306
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/AbstractNodeVisitor.php';
305307
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Attribute.php';
306308
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/ConstExprArrayItemNode.php';
@@ -364,6 +366,7 @@ function isPHPStanTestPreloaded(): bool
364366
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/ConditionalTypeForParameterNode.php';
365367
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/ConditionalTypeNode.php';
366368
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/ConstTypeNode.php';
369+
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/FullyQualifiedNameNode.php';
367370
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/GenericTypeNode.php';
368371
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/IdentifierTypeNode.php';
369372
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/IntersectionTypeNode.php';
@@ -372,6 +375,7 @@ function isPHPStanTestPreloaded(): bool
372375
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/ObjectShapeItemNode.php';
373376
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/ObjectShapeNode.php';
374377
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/OffsetAccessTypeNode.php';
378+
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/RelativeNameNode.php';
375379
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/ThisTypeNode.php';
376380
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Ast/Type/UnionTypeNode.php';
377381
require_once __DIR__ . '/vendor/phpstan/phpdoc-parser/src/Parser/ConstExprParser.php';

‎rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
2525
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
2626
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
27+
use PHPStan\PhpDocParser\Ast\Type\NameNode;
2728
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
2829
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
2930
use Rector\NodeManipulator\StmtsManipulator;
@@ -281,6 +282,9 @@ private function isGenericTypeOfNewClass(New_ $new, VarTagValueNode $varTagValue
281282
return false;
282283
}
283284

284-
return strcasecmp($varTagValueNode->type->type->name, $newClassName) === 0;
285+
$genericName = $varTagValueNode->type->type;
286+
$genericClassName = $genericName instanceof NameNode ? $genericName->toString() : $genericName->name;
287+
288+
return strcasecmp($genericClassName, $newClassName) === 0;
285289
}
286290
}

‎rules/TypeDeclaration/Rector/Class_/ChildDoctrineRepositoryClassTypeRector.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ private function resolveEntityClassnameFromPhpDoc(Class_ $class): ?string
166166
}
167167

168168
$genericTypeNode = $extendsTagValueNode->type;
169-
if ($genericTypeNode->type->name !== 'EntityRepository') {
169+
if (! $genericTypeNode->type instanceof IdentifierTypeNode || $genericTypeNode->type->name !== 'EntityRepository') {
170170
return null;
171171
}
172172

‎src/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\PhpDocParser\Ast\AbstractNodeVisitor;
99
use PHPStan\PhpDocParser\Ast\Node;
1010
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
11+
use PHPStan\PhpDocParser\Ast\Type\NameNode;
1112
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
1213
use PHPStan\Type\Generic\TemplateObjectType;
1314
use PHPStan\Type\ObjectType;
@@ -58,7 +59,7 @@ public function beforeTraverse(array $nodes): ?array
5859

5960
public function enterNode(Node $node): ?Node
6061
{
61-
if (! $node instanceof IdentifierTypeNode) {
62+
if (! $node instanceof IdentifierTypeNode && ! $node instanceof NameNode) {
6263
return null;
6364
}
6465

@@ -72,7 +73,7 @@ public function enterNode(Node $node): ?Node
7273
}
7374

7475
// make sure to compare FQNs
75-
$objectType = $this->ensureFQCNObject($staticType, $node->name);
76+
$objectType = $this->ensureFQCNObject($staticType, $node instanceof NameNode ? $node->toCodeString() : $node->name);
7677

7778
foreach ($this->oldToNewTypes as $oldToNewType) {
7879
$oldType = $oldToNewType->getOldType();

‎src/NodeTypeResolver/PhpDocNodeVisitor/NameImportingPhpDocNodeVisitor.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\PhpDocParser\Ast\AbstractNodeVisitor;
1010
use PHPStan\PhpDocParser\Ast\Node;
1111
use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode;
12+
use PHPStan\PhpDocParser\Ast\Type\FullyQualifiedNameNode;
1213
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
1314
use PHPStan\Reflection\ReflectionProvider;
1415
use PHPStan\Type\Type;
@@ -59,6 +60,16 @@ public function enterNode(Node $node): ?Node
5960
return $node;
6061
}
6162

63+
// e.g. from Type::toPhpDocNode(); import it the same way as a written \Foo\Bar
64+
if ($node instanceof FullyQualifiedNameNode) {
65+
$fullyQualifiedNameNode = $node;
66+
$node = new IdentifierTypeNode($fullyQualifiedNameNode->toCodeString());
67+
$node->setAttribute(
68+
PhpDocAttributeKey::PARENT,
69+
$fullyQualifiedNameNode->getAttribute(PhpDocAttributeKey::PARENT)
70+
);
71+
}
72+
6273
if (! $node instanceof IdentifierTypeNode) {
6374
return null;
6475
}

‎src/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ private function hasOnlySameGenericTypes(UnionTypeNode $unionTypeNode): bool
147147
return false;
148148
}
149149

150+
if (! $unionedTypeNode->type instanceof IdentifierTypeNode) {
151+
return false;
152+
}
153+
150154
$genericTypeName ??= $unionedTypeNode->type->name;
151155
if ($genericTypeName !== $unionedTypeNode->type->name) {
152156
return false;

0 commit comments

Comments
 (0)