@@ -987,47 +987,35 @@ private function specifyTypesForConstantBinaryExpression(
987
987
$ argType = $ scope ->getType ($ exprNode ->getArgs ()[0 ]->value );
988
988
989
989
if (count ($ exprNode ->getArgs ()) === 1 ) {
990
- $ isNormalCount = true ;
990
+ $ isNormalCount = TrinaryLogic:: createYes () ;
991
991
} else {
992
992
$ mode = $ scope ->getType ($ exprNode ->getArgs ()[1 ]->value );
993
- if (!$ mode ->isInteger ()->yes ()) {
994
- return new SpecifiedTypes ();
995
- }
996
-
997
- $ isNormalCount = (new ConstantIntegerType (COUNT_NORMAL ))->isSuperTypeOf ($ mode )->yes ();
998
- if (!$ isNormalCount ) {
999
- $ isNormalCount = $ argType ->getIterableValueType ()->isArray ()->no ();
1000
- }
993
+ $ isNormalCount = (new ConstantIntegerType (COUNT_NORMAL ))->isSuperTypeOf ($ mode )->or ($ argType ->getIterableValueType ()->isArray ()->negate ());
1001
994
}
1002
995
1003
996
if (
1004
- $ isNormalCount
997
+ $ isNormalCount-> yes ()
1005
998
&& $ argType instanceof UnionType
1006
- && $ argType ->isList ()->yes ()
1007
999
) {
1008
1000
$ result = [];
1009
1001
foreach ($ argType ->getTypes () as $ innerType ) {
1010
- if (!$ innerType ->isConstantArray ()->yes ()) {
1011
- $ result = null ;
1012
- break ;
1013
- }
1014
-
1015
1002
$ arraySize = $ innerType ->getArraySize ();
1016
- if (!$ arraySize instanceof ConstantIntegerType) {
1017
- $ result = null ;
1018
- break ;
1003
+ $ isSize = $ constantType ->isSuperTypeOf ($ arraySize );
1004
+ if ($ context ->truthy ()) {
1005
+ if ($ isSize ->no ()) {
1006
+ continue ;
1007
+ }
1019
1008
}
1020
-
1021
- if (!$ constantType ->isSuperTypeOf ($ arraySize )->yes ()) {
1022
- continue ;
1009
+ if ($ context ->falsey ()) {
1010
+ if (!$ isSize ->yes ()) {
1011
+ continue ;
1012
+ }
1023
1013
}
1024
1014
1025
1015
$ result [] = $ innerType ;
1026
1016
}
1027
1017
1028
- if ($ result !== null ) {
1029
- return $ this ->create ($ exprNode ->getArgs ()[0 ]->value , TypeCombinator::union (...$ result ), $ context , false , $ scope , $ rootExpr );
1030
- }
1018
+ return $ this ->create ($ exprNode ->getArgs ()[0 ]->value , TypeCombinator::union (...$ result ), $ context , false , $ scope , $ rootExpr );
1031
1019
}
1032
1020
1033
1021
if ($ context ->truthy () || $ constantType ->getValue () === 0 ) {
@@ -1038,7 +1026,7 @@ private function specifyTypesForConstantBinaryExpression(
1038
1026
1039
1027
if ($ argType ->isArray ()->yes ()) {
1040
1028
$ funcTypes = $ this ->create ($ exprNode , $ constantType , $ context , false , $ scope , $ rootExpr );
1041
- if ($ isNormalCount && $ argType ->isList ()->yes () && $ context ->truthy () && $ constantType ->getValue () < ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT ) {
1029
+ if ($ isNormalCount-> yes () && $ argType ->isList ()->yes () && $ context ->truthy () && $ constantType ->getValue () < ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT ) {
1042
1030
$ valueTypesBuilder = ConstantArrayTypeBuilder::createEmpty ();
1043
1031
$ itemType = $ argType ->getIterableValueType ();
1044
1032
for ($ i = 0 ; $ i < $ constantType ->getValue (); $ i ++) {
0 commit comments