Skip to content
Open
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
10 changes: 9 additions & 1 deletion src/Types/AbstractList.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,16 @@ public function __toString(): string
return 'array<' . $this->keyType . ',' . $this->valueType . '>';
}

// the "(...)[]" syntax is less common
// and not visually distinctive from conditional types and callables
// additionally, it significantly differs from PHP native type hint
if ($this->valueType instanceof Compound) {
return '(' . $this->valueType . ')[]';
return 'array<' . $this->valueType . '>';
}

// 'foo bar'[] or array{a: int}[] is not readable
if (preg_match('/[^\w\\\\]/', (string) $this->valueType)) {
return 'array<' . $this->valueType . '>';
}

return $this->valueType . '[]';
Expand Down
Loading