diff --git a/src/Analyser/TypeSpecifier.php b/src/Analyser/TypeSpecifier.php index e415388a17..81db806b71 100644 --- a/src/Analyser/TypeSpecifier.php +++ b/src/Analyser/TypeSpecifier.php @@ -376,6 +376,11 @@ public function specifyTypesInCondition( && $expr->left->name instanceof Name && strtolower((string) $expr->left->name) === 'count' && $rightType instanceof ConstantIntegerType + && ( + !$expr->right instanceof FuncCall + || !$expr->right->name instanceof Name + || strtolower((string) $expr->right->name) !== 'count' + ) ) { $inverseOperator = $expr instanceof Node\Expr\BinaryOp\Smaller ? new Node\Expr\BinaryOp\SmallerOrEqual($expr->right, $expr->left) diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 4502582293..74d540b006 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -291,6 +291,14 @@ public function testBug4097(): void $this->assertCount(0, $errors); } + public function testBug4300(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-4300.php'); + $this->assertCount(1, $errors); + $this->assertSame('Comparison operation ">" between 0 and 0 is always false.', $errors[0]->getMessage()); + $this->assertSame(13, $errors[0]->getLine()); + } + /** * @param string $file * @return \PHPStan\Analyser\Error[] diff --git a/tests/PHPStan/Analyser/data/bug-4300.php b/tests/PHPStan/Analyser/data/bug-4300.php new file mode 100644 index 0000000000..46895b0456 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-4300.php @@ -0,0 +1,18 @@ + count($column2) ? 2 : 1; + + return $column; + } + +}