@@ -709,16 +709,18 @@ private static function reduceArrays(array $constantArrays): array
709709$ arraysToProcess [] = $ constantArray ;
710710}
711711
712- for ($ i = 0 ; $ i < count ($ arraysToProcess ); $ i ++) {
713- for ($ j = $ i + 1 ; $ j < count ( $ arraysToProcess ) ; $ j ++) {
712+ for ($ i = 0 , $ arraysToProcessCount = count ($ arraysToProcess ); $ i < $ arraysToProcessCount ; $ i ++) {
713+ for ($ j = $ i + 1 ; $ j < $ arraysToProcessCount ; $ j ++) {
714714if ($ arraysToProcess [$ j ]->isKeysSupersetOf ($ arraysToProcess [$ i ])) {
715715$ arraysToProcess [$ j ] = $ arraysToProcess [$ j ]->mergeWith ($ arraysToProcess [$ i ]);
716716array_splice ($ arraysToProcess , $ i --, 1 );
717+ $ arraysToProcessCount --;
717718continue 2 ;
718719
719720} elseif ($ arraysToProcess [$ i ]->isKeysSupersetOf ($ arraysToProcess [$ j ])) {
720721$ arraysToProcess [$ i ] = $ arraysToProcess [$ i ]->mergeWith ($ arraysToProcess [$ j ]);
721722array_splice ($ arraysToProcess , $ j --, 1 );
723+ $ arraysToProcessCount --;
722724continue 1 ;
723725}
724726}
@@ -789,15 +791,17 @@ public static function intersect(Type ...$types): Type
789791
790792return $ union ;
791793}
794+ $ typesCount = count ($ types );
792795
793796// transform A & (B & C) to A & B & C
794- for ($ i = 0 ; $ i < count ( $ types ) ; $ i ++) {
797+ for ($ i = 0 ; $ i < $ typesCount ; $ i ++) {
795798$ type = $ types [$ i ];
796799if (!($ type instanceof IntersectionType)) {
797800continue ;
798801}
799802
800803array_splice ($ types , $ i --, 1 , $ type ->getTypes ());
804+ $ typesCount = count ($ types );
801805}
802806
803807// transform IntegerType & ConstantIntegerType to ConstantIntegerType
@@ -808,7 +812,6 @@ public static function intersect(Type ...$types): Type
808812// transform callable & int to never
809813// transform A & ~A to never
810814// transform int & string to never
811- $ typesCount = count ($ types );
812815for ($ i = 0 ; $ i < $ typesCount ; $ i ++) {
813816for ($ j = $ i + 1 ; $ j < $ typesCount ; $ j ++) {
814817if ($ types [$ j ] instanceof SubtractableType) {
0 commit comments