5959use  function  count ;
6060use  function  implode ;
6161use  function  in_array ;
62+ use  function  is_bool ;
6263use  function  is_int ;
6364use  function  is_string ;
6465use  function  min ;
@@ -76,6 +77,8 @@ class ConstantArrayType extends ArrayType implements ConstantType
7677
7778private  const  DESCRIBE_LIMIT  = 8 ;
7879
80+ private  TrinaryLogic $ isList
81+ 
7982/** @var self[]|null */ 
8083private  ?array  $ allArraysnull ;
8184
@@ -94,7 +97,7 @@ public function __construct(
9497private  array  $ valueTypes
9598int |array  $ nextAutoIndexes0 ],
9699private  array  $ optionalKeys
97- private   bool  $ isListfalse ,
100+ bool | TrinaryLogic $ isListfalse ,
98101)
99102{
100103assert (count ($ keyTypescount ($ valueTypes
@@ -108,13 +111,18 @@ public function __construct(
108111$ keyTypesCountcount ($ this keyTypes );
109112if  ($ keyTypesCount0 ) {
110113$ keyTypenew  NeverType (true );
111- $ this -> isList  = true ;
114+ $ isListTrinaryLogic:: createYes () ;
112115} elseif  ($ keyTypesCount1 ) {
113116$ keyType$ this keyTypes [0 ];
114117} else  {
115118$ keyTypenew  UnionType ($ this keyTypes );
116119}
117120
121+ if  (is_bool ($ isList
122+ $ isListcreateFromBoolean ($ isList
123+ }
124+ $ this isList  = $ isList
125+ 
118126parent ::__construct (
119127$ keyType
120128count ($ valueTypes0  ? TypeCombinator::union (...$ valueTypesnew  NeverType (true ),
@@ -192,7 +200,7 @@ public function getAllArrays(): array
192200$ keysarray_merge ($ requiredKeys$ combination
193201sort ($ keys
194202
195- if  ($ this isList  && array_keys ($ keysarray_values ($ keys
203+ if  ($ this isList -> yes ()  && array_keys ($ keysarray_values ($ keys
196204continue ;
197205}
198206
@@ -841,7 +849,7 @@ public function shuffleArray(): Type
841849if  ($ isIterableAtLeastOnceyes ()) {
842850$ generalizedArrayintersect ($ generalizedArraynew  NonEmptyArrayType ());
843851}
844- if  ($ valuesArrayisList ) {
852+ if  ($ valuesArrayisList -> yes () ) {
845853$ generalizedArrayintersectWith ($ generalizedArray
846854}
847855
@@ -933,7 +941,7 @@ public function isConstantArray(): TrinaryLogic
933941
934942public  function  isList (): TrinaryLogic 
935943{
936- return  TrinaryLogic:: createFromBoolean ( $ this isList ) ;
944+ return  $ this isList ;
937945}
938946
939947/** @deprecated Use popArray() instead */ 
@@ -1122,7 +1130,7 @@ public function reverse(bool $preserveKeys = false): self
11221130$ keyTypesReversedKeysarray_keys ($ keyTypesReversed
11231131$ optionalKeysarray_map (static  fn  (int  $ optionalKeyint  => $ keyTypesReversedKeys$ optionalKey$ this optionalKeys );
11241132
1125- $ reversednew  self ($ keyTypesarray_reverse ($ this valueTypes ), $ this nextAutoIndexes , $ optionalKeysfalse );
1133+ $ reversednew  self ($ keyTypesarray_reverse ($ this valueTypes ), $ this nextAutoIndexes , $ optionalKeysTrinaryLogic:: createNo () );
11261134
11271135return  $ preserveKeys$ reversed$ reversedreindex ();
11281136}
@@ -1161,7 +1169,7 @@ private function reindex(): self
11611169$ autoIndex
11621170}
11631171
1164- return  new  self ($ keyTypes$ this valueTypes , [$ autoIndex$ this optionalKeys , true );
1172+ return  new  self ($ keyTypes$ this valueTypes , [$ autoIndex$ this optionalKeys , TrinaryLogic:: createYes () );
11651173}
11661174
11671175public  function  toBoolean (): BooleanType 
@@ -1247,7 +1255,7 @@ public function generalizeToArray(): Type
12471255if  ($ isIterableAtLeastOnceyes ()) {
12481256$ arrayTypeintersect ($ arrayTypenew  NonEmptyArrayType ());
12491257}
1250- if  ($ this isList ) {
1258+ if  ($ this isList -> yes () ) {
12511259$ arrayTypeintersectWith ($ arrayType
12521260}
12531261
@@ -1279,13 +1287,13 @@ private function getKeysOrValuesArray(array $types): self
12791287$ autoIndexesrange ($ countcount ($ this optionalKeys ), $ count
12801288assert ($ autoIndexes
12811289
1282- if  ($ this isList ) {
1290+ if  ($ this isList -> yes () ) {
12831291// Optimized version for lists: Assume that if a later key exists, then earlier keys also exist. 
12841292$ keyTypesarray_map (
12851293static  fn  (int  $ iConstantIntegerType new  ConstantIntegerType ($ i
12861294array_keys ($ types
12871295);
1288- return  new  self ($ keyTypes$ types$ autoIndexes$ this optionalKeys , true );
1296+ return  new  self ($ keyTypes$ types$ autoIndexes$ this optionalKeys , TrinaryLogic:: createYes () );
12891297}
12901298
12911299$ keyTypes
@@ -1314,7 +1322,7 @@ private function getKeysOrValuesArray(array $types): self
13141322$ maxIndex
13151323}
13161324
1317- return  new  self ($ keyTypes$ valueTypes$ autoIndexes$ optionalKeystrue );
1325+ return  new  self ($ keyTypes$ valueTypes$ autoIndexes$ optionalKeysTrinaryLogic:: createYes () );
13181326}
13191327
13201328/** @deprecated Use getArraySize() instead */ 
@@ -1539,7 +1547,7 @@ public function mergeWith(self $otherArray): self
15391547$ nextAutoIndexesarray_values (array_unique (array_merge ($ this nextAutoIndexes , $ otherArraynextAutoIndexes )));
15401548sort ($ nextAutoIndexes
15411549
1542- return  new  self ($ this keyTypes , $ valueTypes$ nextAutoIndexes$ optionalKeys$ this isList  &&  $ otherArrayisList );
1550+ return  new  self ($ this keyTypes , $ valueTypes$ nextAutoIndexes$ optionalKeys$ this isList -> and ( $ otherArrayisList ) );
15431551}
15441552
15451553/** 
@@ -1680,7 +1688,7 @@ public function getFiniteTypes(): array
16801688 */ 
16811689public  static  function  __set_state (array  $ propertiesType 
16821690{
1683- return  new  self ($ properties'keyTypes ' ], $ properties'valueTypes ' ], $ properties'nextAutoIndexes ' ] ?? $ properties'nextAutoIndex ' ], $ properties'optionalKeys ' ] ?? []);
1691+ return  new  self ($ properties'keyTypes ' ], $ properties'valueTypes ' ], $ properties'nextAutoIndexes ' ] ?? $ properties'nextAutoIndex ' ], $ properties'optionalKeys ' ] ?? [],  $ properties [ ' isList ' ] ?? TrinaryLogic:: createNo () );
16841692}
16851693
16861694}
0 commit comments