Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Ast/Type/ArrayShapeUnsealedTypeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ class ArrayShapeUnsealedTypeNode implements Node

use NodeAttributes;

public TypeNode $valueType;

// declared in source order: the format-preserving printer walks the properties in this order
public ?TypeNode $keyType = null;

public TypeNode $valueType;

public function __construct(TypeNode $valueType, ?TypeNode $keyType)
{
$this->valueType = $valueType;
Expand Down
34 changes: 34 additions & 0 deletions tests/PHPStan/Printer/PrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3060,6 +3060,40 @@ public function enterNode(Node $node)

},
];

yield [
'/** @return array{foo: Foo, ...<string, mixed>} */',
'/** @return array{foo: Bar, ...<string, mixed>} */',
new class extends AbstractNodeVisitor {

public function enterNode(Node $node)
{
if ($node instanceof IdentifierTypeNode && $node->name === 'Foo') {
return new IdentifierTypeNode('Bar');
}

return $node;
}

},
];

yield [
'/** @return array{foo: int, ...< Foo , Baz >} */',
'/** @return array{foo: int, ...< Bar , Baz >} */',
new class extends AbstractNodeVisitor {

public function enterNode(Node $node)
{
if ($node instanceof IdentifierTypeNode && $node->name === 'Foo') {
$node->name = 'Bar';
}

return $node;
}

},
];
}

/**
Expand Down
Loading