Skip to content

Commit 0bea0f2

Browse files
committed
Added regression test
1 parent 5b6cb3a commit 0bea0f2

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,10 @@ public function testBug5984(): void
229229
$this->analyse([__DIR__ . '/data/bug-5984.php'], []);
230230
}
231231

232+
public function testBug6702(): void
233+
{
234+
$this->treatPhpDocTypesAsCertain = true;
235+
$this->analyse([__DIR__ . '/data/bug-6702.php'], []);
236+
}
237+
232238
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug6702;
4+
5+
interface LineScanner
6+
{
7+
function isDone(): bool;
8+
9+
function getColumn(): int;
10+
11+
/**
12+
* Reads the char at the current position and moves the cursor.
13+
* @phpstan-impure
14+
*/
15+
function readChar(): string;
16+
17+
function peekChar(int $offset = 0): string;
18+
19+
function scanChar(string $char): bool;
20+
}
21+
22+
function minimumIndentation(LineScanner $scanner): ?int
23+
{
24+
while (!$scanner->isDone() && $scanner->readChar() !== "\n") {
25+
}
26+
27+
if ($scanner->isDone()) {
28+
return $scanner->peekChar(-1) === "\n" ? -1 : null;
29+
}
30+
31+
$min = null;
32+
while (!$scanner->isDone()) {
33+
// Consume the indentation
34+
while (!$scanner->isDone()) {
35+
$next = $scanner->peekChar();
36+
if ($next !== ' ' && $next !== "\t") {
37+
break;
38+
}
39+
$scanner->readChar();
40+
}
41+
42+
if ($scanner->isDone() || $scanner->scanChar("\n")) {
43+
continue;
44+
}
45+
46+
$min = $min === null ? $scanner->getColumn() : min($min, $scanner->getColumn());
47+
48+
// Consume the rest of the line
49+
while (!$scanner->isDone() && $scanner->readChar() !== "\n") {
50+
}
51+
}
52+
53+
return $min ?? -1;
54+
}

0 commit comments

Comments
 (0)