|
12 | 12 | use PHPStan\PhpDocParser\Ast\Node;
|
13 | 13 | use PHPStan\PhpDocParser\Ast\NodeTraverser;
|
14 | 14 | use PHPStan\PhpDocParser\Ast\NodeVisitor;
|
| 15 | +use PHPStan\PhpDocParser\Ast\PhpDoc\Doctrine\DoctrineAnnotation; |
| 16 | +use PHPStan\PhpDocParser\Ast\PhpDoc\Doctrine\DoctrineArgument; |
| 17 | +use PHPStan\PhpDocParser\Ast\PhpDoc\Doctrine\DoctrineArray; |
15 | 18 | use PHPStan\PhpDocParser\Ast\PhpDoc\Doctrine\DoctrineArrayItem;
|
16 | 19 | use PHPStan\PhpDocParser\Ast\PhpDoc\MethodTagValueNode;
|
17 | 20 | use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
|
|
46 | 49 | use function array_unshift;
|
47 | 50 | use function array_values;
|
48 | 51 | use function count;
|
| 52 | +use const PHP_EOL; |
49 | 53 |
|
50 | 54 | class PrinterTest extends TestCase
|
51 | 55 | {
|
@@ -1532,6 +1536,105 @@ public function enterNode(Node $node)
|
1532 | 1536 |
|
1533 | 1537 | },
|
1534 | 1538 | ];
|
| 1539 | + |
| 1540 | + yield [ |
| 1541 | + '/** @Foo() */', |
| 1542 | + '/** @Foo(1, 2, 3) */', |
| 1543 | + new class extends AbstractNodeVisitor { |
| 1544 | + |
| 1545 | + public function enterNode(Node $node) |
| 1546 | + { |
| 1547 | + if ($node instanceof DoctrineAnnotation) { |
| 1548 | + $node->arguments = [ |
| 1549 | + new DoctrineArgument(null, new ConstExprIntegerNode('1')), |
| 1550 | + new DoctrineArgument(null, new ConstExprIntegerNode('2')), |
| 1551 | + new DoctrineArgument(null, new ConstExprIntegerNode('3')), |
| 1552 | + ]; |
| 1553 | + } |
| 1554 | + |
| 1555 | + return $node; |
| 1556 | + } |
| 1557 | + |
| 1558 | + }, |
| 1559 | + ]; |
| 1560 | + |
| 1561 | + yield [ |
| 1562 | + '/** @Foo( |
| 1563 | + * 1, |
| 1564 | + * 2, |
| 1565 | + * ) */', |
| 1566 | + '/** @Foo( |
| 1567 | + * 1, |
| 1568 | + * 2, |
| 1569 | + * 3, |
| 1570 | + * ) */', |
| 1571 | + new class extends AbstractNodeVisitor { |
| 1572 | + |
| 1573 | + public function enterNode(Node $node) |
| 1574 | + { |
| 1575 | + if ($node instanceof DoctrineAnnotation) { |
| 1576 | + $node->arguments[] = new DoctrineArgument(null, new ConstExprIntegerNode('3')); |
| 1577 | + } |
| 1578 | + |
| 1579 | + return $node; |
| 1580 | + } |
| 1581 | + |
| 1582 | + }, |
| 1583 | + ]; |
| 1584 | + |
| 1585 | + yield [ |
| 1586 | + '/**' . PHP_EOL . |
| 1587 | + ' * @X({' . PHP_EOL . |
| 1588 | + ' * 1,' . PHP_EOL . |
| 1589 | + ' * 2' . PHP_EOL . |
| 1590 | + ' * , ' . PHP_EOL . |
| 1591 | + ' * 3,' . PHP_EOL . |
| 1592 | + ' * }' . PHP_EOL . |
| 1593 | + ' * )' . PHP_EOL . |
| 1594 | + ' */', |
| 1595 | + '/**' . PHP_EOL . |
| 1596 | + ' * @X({' . PHP_EOL . |
| 1597 | + ' * 1,' . PHP_EOL . |
| 1598 | + ' * 2' . PHP_EOL . |
| 1599 | + ' * , ' . PHP_EOL . |
| 1600 | + ' * 3,' . PHP_EOL . |
| 1601 | + ' * 4,' . PHP_EOL . |
| 1602 | + ' * }' . PHP_EOL . |
| 1603 | + ' * )' . PHP_EOL . |
| 1604 | + ' */', |
| 1605 | + new class extends AbstractNodeVisitor { |
| 1606 | + |
| 1607 | + public function enterNode(Node $node) |
| 1608 | + { |
| 1609 | + if ($node instanceof DoctrineArray) { |
| 1610 | + $node->items[] = new DoctrineArrayItem(null, new ConstExprIntegerNode('4')); |
| 1611 | + } |
| 1612 | + |
| 1613 | + return $node; |
| 1614 | + } |
| 1615 | + |
| 1616 | + }, |
| 1617 | + ]; |
| 1618 | + |
| 1619 | + yield [ |
| 1620 | + '/** @Foo() */', |
| 1621 | + '/** @Bar() */', |
| 1622 | + new class extends AbstractNodeVisitor { |
| 1623 | + |
| 1624 | + public function enterNode(Node $node) |
| 1625 | + { |
| 1626 | + if ($node instanceof PhpDocTagNode) { |
| 1627 | + $node->name = '@Bar'; |
| 1628 | + } |
| 1629 | + if ($node instanceof DoctrineAnnotation) { |
| 1630 | + $node->name = '@Bar'; |
| 1631 | + } |
| 1632 | + |
| 1633 | + return $node; |
| 1634 | + } |
| 1635 | + |
| 1636 | + }, |
| 1637 | + ]; |
1535 | 1638 | }
|
1536 | 1639 |
|
1537 | 1640 | /**
|
|
0 commit comments