Skip to content

Commit 4e7b249

Browse files
committed
Change array syntax to more commonly used
* to visually distinguish from conditional types like ($foo ? false : string[]) and callable syntax * to improve readability for array shapes and arrays of literals * to visually more closely align it with PHP native type hint
1 parent fb05a34 commit 4e7b249

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/Types/AbstractList.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,16 @@ public function __toString(): string
8484
return 'array<' . $this->keyType . ',' . $this->valueType . '>';
8585
}
8686

87+
// the "(...)[]" syntax is less common
88+
// and not visually distinctive from conditional types and callables
89+
// additionally, it significantly differs from PHP native type hint
8790
if ($this->valueType instanceof Compound) {
88-
return '(' . $this->valueType . ')[]';
91+
return 'array<' . $this->valueType . '>';
92+
}
93+
94+
// 'foo bar'[] or array{a: int}[] is not readable
95+
if (preg_match('/[^\w\\\\]/', (string) $this->valueType)) {
96+
return 'array<' . $this->valueType . '>';
8997
}
9098

9199
return $this->valueType . '[]';

0 commit comments

Comments
 (0)