forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-6702.php
More file actions
54 lines (41 loc) · 1.05 KB
/
bug-6702.php
File metadata and controls
54 lines (41 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php declare(strict_types=1);
namespace Bug6702;
interface LineScanner
{
function isDone(): bool;
function getColumn(): int;
/**
* Reads the char at the current position and moves the cursor.
* @phpstan-impure
*/
function readChar(): string;
function peekChar(int $offset = 0): string;
function scanChar(string $char): bool;
}
function minimumIndentation(LineScanner $scanner): ?int
{
while (!$scanner->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;
}