From ec26a001da805605a9bbbbdfb8e55182ee0ad383 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 19 Feb 2021 17:25:15 +0100 Subject: [PATCH] Symbol discovery - fixed looking for functions returning references --- .../OptimizedDirectorySourceLocator.php | 2 +- .../OptimizedDirectorySourceLocatorTest.php | 10 ++++++++++ .../SourceLocator/data/directory/b.php | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php b/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php index 67cd263cee..961c7b50b8 100644 --- a/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php +++ b/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocator.php @@ -226,7 +226,7 @@ private function findSymbols(string $file): array preg_match_all('{ (?: - \b(?])(?Pclass|interface|trait|function) \s++ (?P[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+) + \b(?])(?Pclass|interface|trait|function) \s++ (?P&\s*)? (?P[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+) | \b(?])(?Pnamespace) (?P\s++[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\s*+\\\\\s*+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+)? \s*+ [\{;] ) }ix', $contents, $matches); diff --git a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php index 30396d4303..3bfd453866 100644 --- a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php +++ b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php @@ -81,6 +81,16 @@ public function dataFunctionExists(): array 'doBaz', 'b.php', ], + [ + 'get_smarty', + 'get_smarty', + 'b.php', + ], + [ + 'get_smarty2', + 'get_smarty2', + 'b.php', + ], ]; } diff --git a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/data/directory/b.php b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/data/directory/b.php index 34ecde8b4a..47b700b0ea 100644 --- a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/data/directory/b.php +++ b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/data/directory/b.php @@ -19,3 +19,17 @@ function doBaz() { } + +function &get_smarty() +{ + global $smarty; + + return $smarty; +} + +function & get_smarty2() +{ + global $smarty; + + return $smarty; +}