@@ -369,6 +369,7 @@ public function specifyTypesInCondition(
369369 $ subtractedType = $ scope ->getType ($ expr ->right ->right );
370370 if (
371371 $ countArgType ->isList ()->yes ()
372+ && $ this ->isNormalCountCall ($ expr ->right ->left , $ countArgType , $ scope )->yes ()
372373 && IntegerRangeType::fromInterval (1 , null )->isSuperTypeOf ($ subtractedType )->yes ()
373374 ) {
374375 $ arrayArg = $ expr ->right ->left ->getArgs ()[0 ]->value ;
@@ -1239,6 +1240,16 @@ public function specifyTypesInCondition(
12391240 return (new SpecifiedTypes ([], []))->setRootExpr ($ expr );
12401241 }
12411242
1243+ private function isNormalCountCall (FuncCall $ countFuncCall , Type $ typeToCount , Scope $ scope ): TrinaryLogic
1244+ {
1245+ if (count ($ countFuncCall ->getArgs ()) === 1 ) {
1246+ return TrinaryLogic::createYes ();
1247+ }
1248+
1249+ $ mode = $ scope ->getType ($ countFuncCall ->getArgs ()[1 ]->value );
1250+ return (new ConstantIntegerType (COUNT_NORMAL ))->isSuperTypeOf ($ mode )->result ->or ($ typeToCount ->getIterableValueType ()->isArray ()->negate ());
1251+ }
1252+
12421253 private function specifyTypesForCountFuncCall (
12431254 FuncCall $ countFuncCall ,
12441255 Type $ type ,
@@ -1248,18 +1259,11 @@ private function specifyTypesForCountFuncCall(
12481259 Expr $ rootExpr ,
12491260 ): ?SpecifiedTypes
12501261 {
1251- if (count ($ countFuncCall ->getArgs ()) === 1 ) {
1252- $ isNormalCount = TrinaryLogic::createYes ();
1253- } else {
1254- $ mode = $ scope ->getType ($ countFuncCall ->getArgs ()[1 ]->value );
1255- $ isNormalCount = (new ConstantIntegerType (COUNT_NORMAL ))->isSuperTypeOf ($ mode )->result ->or ($ type ->getIterableValueType ()->isArray ()->negate ());
1256- }
1257-
12581262 $ isConstantArray = $ type ->isConstantArray ();
12591263 $ isList = $ type ->isList ();
12601264 $ oneOrMore = IntegerRangeType::fromInterval (1 , null );
12611265 if (
1262- !$ isNormalCount ->yes ()
1266+ !$ this -> isNormalCountCall ( $ countFuncCall , $ type , $ scope ) ->yes ()
12631267 || (!$ isConstantArray ->yes () && !$ isList ->yes ())
12641268 || !$ oneOrMore ->isSuperTypeOf ($ sizeType )->yes ()
12651269 || $ sizeType ->isSuperTypeOf ($ type ->getArraySize ())->yes ()
0 commit comments