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 . '[]';