2222 */
2323abstract class AbstractList implements Type
2424{
25- /** @var Type */
25+ /** @var Type|null */
2626 protected $ valueType ;
2727
2828 /** @var Type|null */
@@ -31,15 +31,15 @@ abstract class AbstractList implements Type
3131 /** @var Type */
3232 protected $ defaultKeyType ;
3333
34+ /** @var Type */
35+ protected $ defaultValueType ;
36+
3437 /**
3538 * Initializes this representation of an array with the given Type.
3639 */
3740 public function __construct (?Type $ valueType = null , ?Type $ keyType = null )
3841 {
39- if ($ valueType === null ) {
40- $ valueType = new Mixed_ ();
41- }
42-
42+ $ this ->defaultValueType = new Mixed_ ();
4343 $ this ->valueType = $ valueType ;
4444 $ this ->defaultKeyType = new Compound ([new String_ (), new Integer ()]);
4545 $ this ->keyType = $ keyType ;
@@ -50,6 +50,11 @@ public function getOriginalKeyType(): ?Type
5050 return $ this ->keyType ;
5151 }
5252
53+ public function getOriginalValueType (): ?Type
54+ {
55+ return $ this ->valueType ;
56+ }
57+
5358 /**
5459 * Returns the type for the keys of this array.
5560 */
@@ -63,20 +68,20 @@ public function getKeyType(): Type
6368 */
6469 public function getValueType (): Type
6570 {
66- return $ this ->valueType ;
71+ return $ this ->valueType ?? $ this -> defaultValueType ;
6772 }
6873
6974 /**
7075 * Returns a rendered output of the Type as it would be used in a DocBlock.
7176 */
7277 public function __toString (): string
7378 {
74- if ($ this ->keyType ) {
75- return 'array< ' . $ this -> keyType . ' , ' . $ this -> valueType . ' > ' ;
79+ if ($ this ->valueType === null ) {
80+ return 'array ' ;
7681 }
7782
78- if ($ this ->valueType instanceof Mixed_ ) {
79- return 'array ' ;
83+ if ($ this ->keyType ) {
84+ return 'array< ' . $ this -> keyType . ' , ' . $ this -> valueType . ' > ' ;
8085 }
8186
8287 if ($ this ->valueType instanceof Compound) {
0 commit comments