Skip to content

Commit a09a98d

Browse files
committed
OptimizedDirectorySourceLocator - fixed crash when parsing Text.php of nl_BE from Faker
1 parent 87b0706 commit a09a98d

File tree

3 files changed

+25362
-0
lines changed

3 files changed

+25362
-0
lines changed

src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ private function findSymbols(string $file): array
203203

204204
// strip heredocs/nowdocs
205205
$contents = preg_replace('{<<<[ \t]*([\'"]?)(\w+)\\1(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r)(?:\s*)\\2(?=\s+|[;,.)])}s', 'null', $contents);
206+
if ($contents === null) {
207+
return ['classes' => [], 'functions' => []];
208+
}
206209
// strip strings
207210
$contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents);
208211
// strip leading non-php code if needed

tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,15 @@ public function testFunctionDoesNotExist(string $functionName): void
135135
$functionReflector->reflect($functionName);
136136
}
137137

138+
public function testBug5525(): void
139+
{
140+
$factory = self::getContainer()->getByType(OptimizedDirectorySourceLocatorFactory::class);
141+
$locator = $factory->createByFiles([__DIR__ . '/data/bug-5525.php']);
142+
$classReflector = new ClassReflector($locator);
143+
$functionReflector = new FunctionReflector($locator, $classReflector);
144+
145+
$this->expectException(IdentifierNotFound::class);
146+
$functionReflector->reflect('spl_autoload_register');
147+
}
148+
138149
}

0 commit comments

Comments
 (0)