From 940acd1e0a740939a84a4869cee1e1dcdc8d7cf3 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 27 Feb 2026 18:52:02 +0100 Subject: [PATCH 1/3] Added regression test --- .../BooleanNotConstantConditionRuleTest.php | 6 +++ .../Rules/Comparison/data/bug-6702.php | 54 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/PHPStan/Rules/Comparison/data/bug-6702.php diff --git a/tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php index 37563611b7e..4f994ad4585 100644 --- a/tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php @@ -229,4 +229,10 @@ public function testBug5984(): void $this->analyse([__DIR__ . '/data/bug-5984.php'], []); } + public function testBug6702(): void + { + $this->treatPhpDocTypesAsCertain = true; + $this->analyse([__DIR__ . '/data/bug-6702.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-6702.php b/tests/PHPStan/Rules/Comparison/data/bug-6702.php new file mode 100644 index 00000000000..a7aff822fc6 --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-6702.php @@ -0,0 +1,54 @@ +isDone() && $scanner->readChar() !== "\n") { + } + + if ($scanner->isDone()) { + return $scanner->peekChar(-1) === "\n" ? -1 : null; + } + + $min = null; + while (!$scanner->isDone()) { + // Consume the indentation + while (!$scanner->isDone()) { + $next = $scanner->peekChar(); + if ($next !== ' ' && $next !== "\t") { + break; + } + $scanner->readChar(); + } + + if ($scanner->isDone() || $scanner->scanChar("\n")) { + continue; + } + + $min = $min === null ? $scanner->getColumn() : min($min, $scanner->getColumn()); + + // Consume the rest of the line + while (!$scanner->isDone() && $scanner->readChar() !== "\n") { + } + } + + return $min ?? -1; +} From 96823372d4502b0d915b9eb56cf84753543dc7d0 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 27 Feb 2026 18:56:27 +0100 Subject: [PATCH 2/3] Added tests --- .../IfConstantConditionRuleTest.php | 7 +++++++ .../Rules/Comparison/data/bug-7699.php | 10 ++++++++++ .../PHPStan/Rules/Variables/IssetRuleTest.php | 8 ++++++++ .../PHPStan/Rules/Variables/data/bug-9503.php | 19 +++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 tests/PHPStan/Rules/Comparison/data/bug-7699.php create mode 100644 tests/PHPStan/Rules/Variables/data/bug-9503.php diff --git a/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php index 2bf30170986..1ecf747d15a 100644 --- a/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php @@ -194,4 +194,11 @@ public function testBug13384b(): void ]); } + public function testBug7699(): void + { + $this->treatPhpDocTypesAsCertain = true; + $this->analyse([__DIR__ . '/data/bug-7699.php'], []); + } + + } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-7699.php b/tests/PHPStan/Rules/Comparison/data/bug-7699.php new file mode 100644 index 00000000000..2c286df1180 --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-7699.php @@ -0,0 +1,10 @@ +analyse([__DIR__ . '/../../Analyser/nsrt/bug-10640.php'], []); } + public function testBug9503(): void + { + $this->treatPhpDocTypesAsCertain = true; + + $this->analyse([__DIR__ . '/data/bug-9503.php'], []); + } + + } diff --git a/tests/PHPStan/Rules/Variables/data/bug-9503.php b/tests/PHPStan/Rules/Variables/data/bug-9503.php new file mode 100644 index 00000000000..2b8f791d15e --- /dev/null +++ b/tests/PHPStan/Rules/Variables/data/bug-9503.php @@ -0,0 +1,19 @@ + 0) { + if (isset($matches[2]) && preg_match('~x2(a)?(b)?~', $matches[2], $matches) > 0) { + if (isset($matches[2])) { + return true; + } + } + } + + return false; + } +} From 07b41e56ffc5e64aad7b481a7303efcad76dcf17 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 27 Feb 2026 18:56:49 +0100 Subject: [PATCH 3/3] cs --- tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php | 1 - tests/PHPStan/Rules/Variables/IssetRuleTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php index 1ecf747d15a..3d4b6e39e4c 100644 --- a/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php @@ -200,5 +200,4 @@ public function testBug7699(): void $this->analyse([__DIR__ . '/data/bug-7699.php'], []); } - } diff --git a/tests/PHPStan/Rules/Variables/IssetRuleTest.php b/tests/PHPStan/Rules/Variables/IssetRuleTest.php index de92b93f9c4..045af8b58b6 100644 --- a/tests/PHPStan/Rules/Variables/IssetRuleTest.php +++ b/tests/PHPStan/Rules/Variables/IssetRuleTest.php @@ -513,5 +513,4 @@ public function testBug9503(): void $this->analyse([__DIR__ . '/data/bug-9503.php'], []); } - }