Skip to content

Commit 0585d62

Browse files
ondrejmirtesphpstan-bot
authored andcommitted
Regression tests
Closes phpstan/phpstan#5984 Closes phpstan/phpstan#9400
1 parent 72b4de4 commit 0585d62

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug9400;
4+
5+
use RuntimeException;
6+
use function PHPStan\Testing\assertType;
7+
8+
function foo(string $foo): void
9+
{
10+
if (!ctype_digit($foo) || ($foo = intval($foo)) < 1) {
11+
throw new RuntimeException();
12+
}
13+
assertType('int<1, max>', $foo);
14+
}

tests/PHPStan/Rules/Comparison/BooleanNotConstantConditionRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,10 @@ public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLast
223223
$this->analyse([__DIR__ . '/data/boolean-not-report-always-true-last-condition.php'], $expectedErrors);
224224
}
225225

226+
public function testBug5984(): void
227+
{
228+
$this->treatPhpDocTypesAsCertain = true;
229+
$this->analyse([__DIR__ . '/data/bug-5984.php'], []);
230+
}
231+
226232
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Bug5984;
4+
5+
interface LineScanner
6+
{
7+
function isDone(): bool;
8+
/**
9+
* @phpstan-impure
10+
*/
11+
function scanChar(string $char): bool;
12+
/**
13+
* @phpstan-impure
14+
*/
15+
function readChar(): string;
16+
17+
function getColumn(): int;
18+
}
19+
20+
class Test
21+
{
22+
public function minimumIndentation(LineScanner $scanner): ?int
23+
{
24+
if ($scanner->isDone() || $scanner->scanChar("\n")) {
25+
return null;
26+
}
27+
28+
$min = $scanner->getColumn();
29+
30+
while (!$scanner->isDone() && $scanner->readChar() !== "\n") {
31+
}
32+
33+
return $min;
34+
}
35+
}

0 commit comments

Comments
 (0)