|
28 | 28 | use PHPStan\PhpDocParser\Ast\PhpDoc\TypeAliasImportTagValueNode;
|
29 | 29 | use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode;
|
30 | 30 | use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
|
| 31 | +use PHPStan\PhpDocParser\Ast\Type\ArrayShapeUnsealedTypeNode; |
31 | 32 | use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode;
|
32 | 33 | use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode;
|
33 | 34 | use PHPStan\PhpDocParser\Ast\Type\CallableTypeParameterNode;
|
|
51 | 52 | use function array_splice;
|
52 | 53 | use function array_unshift;
|
53 | 54 | use function array_values;
|
| 55 | +use function assert; |
54 | 56 | use function count;
|
55 | 57 | use const PHP_EOL;
|
56 | 58 |
|
@@ -1740,6 +1742,76 @@ public function enterNode(Node $node)
|
1740 | 1742 |
|
1741 | 1743 | },
|
1742 | 1744 | ];
|
| 1745 | + |
| 1746 | + yield [ |
| 1747 | + '/** @return array{foo: int, ...} */', |
| 1748 | + '/** @return array{foo: int} */', |
| 1749 | + new class extends AbstractNodeVisitor { |
| 1750 | + |
| 1751 | + public function enterNode(Node $node) |
| 1752 | + { |
| 1753 | + if ($node instanceof ArrayShapeNode) { |
| 1754 | + $node->sealed = true; |
| 1755 | + } |
| 1756 | + |
| 1757 | + return $node; |
| 1758 | + } |
| 1759 | + |
| 1760 | + }, |
| 1761 | + ]; |
| 1762 | + |
| 1763 | + yield [ |
| 1764 | + '/** @return array{foo: int, ...} */', |
| 1765 | + '/** @return array{foo: int, ...<string>} */', |
| 1766 | + new class extends AbstractNodeVisitor { |
| 1767 | + |
| 1768 | + public function enterNode(Node $node) |
| 1769 | + { |
| 1770 | + if ($node instanceof ArrayShapeNode) { |
| 1771 | + $node->unsealedType = new ArrayShapeUnsealedTypeNode(new IdentifierTypeNode('string'), null); |
| 1772 | + } |
| 1773 | + |
| 1774 | + return $node; |
| 1775 | + } |
| 1776 | + |
| 1777 | + }, |
| 1778 | + ]; |
| 1779 | + |
| 1780 | + yield [ |
| 1781 | + '/** @return array{foo: int, ...<string>} */', |
| 1782 | + '/** @return array{foo: int, ...<int, string>} */', |
| 1783 | + new class extends AbstractNodeVisitor { |
| 1784 | + |
| 1785 | + public function enterNode(Node $node) |
| 1786 | + { |
| 1787 | + if ($node instanceof ArrayShapeNode) { |
| 1788 | + assert($node->unsealedType !== null); |
| 1789 | + $node->unsealedType->keyType = new IdentifierTypeNode('int'); |
| 1790 | + } |
| 1791 | + |
| 1792 | + return $node; |
| 1793 | + } |
| 1794 | + |
| 1795 | + }, |
| 1796 | + ]; |
| 1797 | + |
| 1798 | + yield [ |
| 1799 | + '/** @return array{foo: int, ...<string>} */', |
| 1800 | + '/** @return array{foo: int} */', |
| 1801 | + new class extends AbstractNodeVisitor { |
| 1802 | + |
| 1803 | + public function enterNode(Node $node) |
| 1804 | + { |
| 1805 | + if ($node instanceof ArrayShapeNode) { |
| 1806 | + $node->sealed = true; |
| 1807 | + $node->unsealedType = null; |
| 1808 | + } |
| 1809 | + |
| 1810 | + return $node; |
| 1811 | + } |
| 1812 | + |
| 1813 | + }, |
| 1814 | + ]; |
1743 | 1815 | }
|
1744 | 1816 |
|
1745 | 1817 | /**
|
|
0 commit comments