Skip to content

Commit 362bc12

Browse files
authored
Merge branch refs/heads/1.21.x into 1.22.x
2 parents e5c48b4 + b0c366d commit 362bc12

File tree

3 files changed

+56
-7
lines changed

3 files changed

+56
-7
lines changed

Diff for: src/Parser/PhpDocParser.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,8 @@ private function enrichWithAttributes(TokenIterator $tokens, Ast\Node $tag, int
137137

138138
if ($this->useIndexAttributes) {
139139
$tokensArray = $tokens->getTokens();
140-
if ($tokensArray[$endIndex][Lexer::TYPE_OFFSET] === Lexer::TOKEN_CLOSE_PHPDOC) {
141-
$endIndex--;
142-
if ($tokensArray[$endIndex][Lexer::TYPE_OFFSET] === Lexer::TOKEN_HORIZONTAL_WS) {
143-
$endIndex--;
144-
}
145-
} elseif ($tokensArray[$endIndex][Lexer::TYPE_OFFSET] === Lexer::TOKEN_PHPDOC_EOL) {
140+
$endIndex--;
141+
if ($tokensArray[$endIndex][Lexer::TYPE_OFFSET] === Lexer::TOKEN_HORIZONTAL_WS) {
146142
$endIndex--;
147143
}
148144

Diff for: tests/PHPStan/Parser/PhpDocParserTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5614,7 +5614,7 @@ public function dataLinesAndIndexes(): iterable
56145614
yield [
56155615
'/** @phpstan-import-type TypeAlias from AnotherClass[] */',
56165616
[
5617-
[1, 1, 8, 12],
5617+
[1, 1, 8, 11],
56185618
],
56195619
];
56205620

Diff for: tests/PHPStan/Printer/PrinterTest.php

+53
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprArrayItemNode;
88
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprArrayNode;
99
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode;
10+
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
1011
use PHPStan\PhpDocParser\Ast\ConstExpr\QuoteAwareConstExprStringNode;
1112
use PHPStan\PhpDocParser\Ast\Node;
1213
use PHPStan\PhpDocParser\Ast\NodeTraverser;
@@ -23,6 +24,7 @@
2324
use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
2425
use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
2526
use PHPStan\PhpDocParser\Ast\Type\CallableTypeParameterNode;
27+
use PHPStan\PhpDocParser\Ast\Type\ConstTypeNode;
2628
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
2729
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
2830
use PHPStan\PhpDocParser\Ast\Type\IntersectionTypeNode;
@@ -1426,6 +1428,57 @@ public function enterNode(Node $node)
14261428

14271429
},
14281430
];
1431+
1432+
yield [
1433+
'/** @param \DateTimeImmutable::ATOM $date */',
1434+
'/** @param DateTimeImmutable::ATOM $date */',
1435+
new class extends AbstractNodeVisitor {
1436+
1437+
public function enterNode(Node $node)
1438+
{
1439+
if ($node instanceof ParamTagValueNode) {
1440+
$node->type = new ConstTypeNode(new ConstFetchNode('DateTimeImmutable', 'ATOM'));
1441+
}
1442+
1443+
return $node;
1444+
}
1445+
1446+
},
1447+
];
1448+
1449+
yield [
1450+
'/** @param \Lorem\Ipsum $ipsum */',
1451+
'/** @param Ipsum $ipsum */',
1452+
new class extends AbstractNodeVisitor {
1453+
1454+
public function enterNode(Node $node)
1455+
{
1456+
if ($node instanceof ParamTagValueNode) {
1457+
$node->type = new IdentifierTypeNode('Ipsum');
1458+
}
1459+
1460+
return $node;
1461+
}
1462+
1463+
},
1464+
];
1465+
1466+
yield [
1467+
'/** @phpstan-import-type Foo from \Bar as Lorem */',
1468+
'/** @phpstan-import-type Foo from Bar as Lorem */',
1469+
new class extends AbstractNodeVisitor {
1470+
1471+
public function enterNode(Node $node)
1472+
{
1473+
if ($node instanceof TypeAliasImportTagValueNode) {
1474+
$node->importedFrom = new IdentifierTypeNode('Bar');
1475+
}
1476+
1477+
return $node;
1478+
}
1479+
1480+
},
1481+
];
14291482
}
14301483

14311484
/**

0 commit comments

Comments
 (0)