@@ -685,6 +685,17 @@ public function isIterableAtLeastOnce(): TrinaryLogic
685
685
return TrinaryLogic::createMaybe ();
686
686
}
687
687
688
+ public function getIterableCount (): Type
689
+ {
690
+ $ optionalKeysCount = count ($ this ->optionalKeys );
691
+ $ totalKeysCount = count ($ this ->getKeyTypes ());
692
+ if ($ optionalKeysCount === 0 ) {
693
+ return new ConstantIntegerType ($ totalKeysCount );
694
+ }
695
+
696
+ return IntegerRangeType::fromInterval ($ totalKeysCount - $ optionalKeysCount , $ totalKeysCount );
697
+ }
698
+
688
699
public function getFirstIterableKeyType (): Type
689
700
{
690
701
$ keyTypes = [];
@@ -979,7 +990,7 @@ private function reindex(): self
979
990
980
991
public function toBoolean (): BooleanType
981
992
{
982
- return $ this ->count ()->toBoolean ();
993
+ return $ this ->getIterableCount ()->toBoolean ();
983
994
}
984
995
985
996
public function toInteger (): Type
@@ -1116,15 +1127,10 @@ public function getValuesArray(): Type
1116
1127
return new self ($ keyTypes , $ valueTypes , $ autoIndex , $ optionalKeys , true );
1117
1128
}
1118
1129
1130
+ /** @deprecated Use getIterableCount() instead */
1119
1131
public function count (): Type
1120
1132
{
1121
- $ optionalKeysCount = count ($ this ->optionalKeys );
1122
- $ totalKeysCount = count ($ this ->getKeyTypes ());
1123
- if ($ optionalKeysCount === 0 ) {
1124
- return new ConstantIntegerType ($ totalKeysCount );
1125
- }
1126
-
1127
- return IntegerRangeType::fromInterval ($ totalKeysCount - $ optionalKeysCount , $ totalKeysCount );
1133
+ return $ this ->getIterableCount ();
1128
1134
}
1129
1135
1130
1136
public function describe (VerbosityLevel $ level ): string
0 commit comments