From 4e7b2494c53b37e6bc97b1f6dcf6ebdcdb19e28d Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Sun, 7 Dec 2025 12:00:18 +0100 Subject: [PATCH] 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 --- src/Types/AbstractList.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Types/AbstractList.php b/src/Types/AbstractList.php index 68c1f88c..746e9dcb 100644 --- a/src/Types/AbstractList.php +++ b/src/Types/AbstractList.php @@ -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 . '[]';