Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'], []);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,10 @@ public function testBug13384b(): void
]);
}

public function testBug7699(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-7699.php'], []);
}

}
54 changes: 54 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-6702.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-7699.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);

namespace Bug7699;

$selections = isset($_GET['x']) ? explode(',', $_GET['x']) : [];
while ($selections && $id = array_shift($selections)) {
if ($selections) {
var_dump('x');
}
}
7 changes: 7 additions & 0 deletions tests/PHPStan/Rules/Variables/IssetRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,11 @@ public function testBug10640(): void
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-10640.php'], []);
}

public function testBug9503(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/data/bug-9503.php'], []);
}

}
19 changes: 19 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-9503.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

namespace Bug9503;

class HelloWorld
{
public function sayHello(string $str): bool
{
if (preg_match('~x(a)?(b)?~', $str, $matches) > 0) {
if (isset($matches[2]) && preg_match('~x2(a)?(b)?~', $matches[2], $matches) > 0) {
if (isset($matches[2])) {
return true;
}
}
}

return false;
}
}
Loading