Skip to content

Commit 98edaa0

Browse files
phpstan-botclaude
andcommitted
Add rule test for bug-6799 to verify no false positive on count() comparison
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0487f0a commit 98edaa0

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ public function testBug13874(): void
288288
$this->analyse([__DIR__ . '/data/bug-13874.php'], []);
289289
}
290290

291+
public function testBug6799(): void
292+
{
293+
$this->analyse([__DIR__ . '/data/bug-6799.php'], []);
294+
}
295+
291296
public function testBug12163(): void
292297
{
293298
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-12163.php'], [
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug6799Rule;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @param string[] $where
9+
* @param string $sqlTableName
10+
* @param mixed[] $filter
11+
* @param string $value
12+
*/
13+
protected function listingAddWhereFilterAtableDefault(array &$where, string $sqlTableName, array $filter, string $value): void
14+
{
15+
if ($value != "" && !empty($filter) && !empty($filter['sql']) && is_string($filter['sql'])) {
16+
$where[] = "`" . $sqlTableName . "`.`" . (string)$filter['sql'] . "` = '" . $value . "'";
17+
}
18+
}
19+
20+
/**
21+
* @param string[] $filterValues
22+
* @param string[] $where
23+
* @param string[] $tables
24+
* @param mixed[] $filters
25+
*/
26+
protected function listingAddWhereFilterAtable(array $filterValues, array &$where, array &$tables, array $filters): void
27+
{
28+
if (!empty($filterValues) && !empty($filters)) {
29+
$whereFilter = array();
30+
foreach ($filterValues as $type => $value) {
31+
call_user_func_array(array($this, 'listingAddWhereFilterAtableDefault'), array(&$whereFilter, 'xxxx', $filters[$type], $value));
32+
}
33+
if (count($whereFilter) > 0) {
34+
$where[] = implode(' OR ', $whereFilter);
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)