diff --git a/src/UsedSymbolExtractor.php b/src/UsedSymbolExtractor.php index cff49c6..371bc61 100644 --- a/src/UsedSymbolExtractor.php +++ b/src/UsedSymbolExtractor.php @@ -411,6 +411,7 @@ private function canBeSymbolName( || $tokenBeforeName[0] === T_AS || $tokenBeforeName[0] === T_FUNCTION || $tokenBeforeName[0] === T_OBJECT_OPERATOR + || $tokenBeforeName[0] === T_NAMESPACE || $tokenBeforeName[0] === (PHP_VERSION_ID > 80000 ? T_NULLSAFE_OBJECT_OPERATOR : -1) || $tokenAfterName[0] === T_INSTEADOF || $tokenAfterName[0] === T_AS diff --git a/tests/UsedSymbolExtractorTest.php b/tests/UsedSymbolExtractorTest.php index 16dc5a0..bc6e397 100644 --- a/tests/UsedSymbolExtractorTest.php +++ b/tests/UsedSymbolExtractorTest.php @@ -12,9 +12,10 @@ class UsedSymbolExtractorTest extends TestCase /** * @param array>> $expectedUsages + * @param array $extensionSymbols * @dataProvider provideVariants */ - public function test(string $path, array $expectedUsages): void + public function test(string $path, array $expectedUsages, array $extensionSymbols = []): void { $code = file_get_contents($path); self::assertNotFalse($code); @@ -23,24 +24,12 @@ public function test(string $path, array $expectedUsages): void self::assertSame( $expectedUsages, - $extractor->parseUsedSymbols( - [ - strtolower('XMLReader') => SymbolKind::CLASSLIKE, - strtolower('PDO') => SymbolKind::CLASSLIKE, - strtolower('json_encode') => SymbolKind::FUNCTION, - strtolower('DDTrace\active_span') => SymbolKind::FUNCTION, - strtolower('DDTrace\root_span') => SymbolKind::FUNCTION, - strtolower('LIBXML_ERR_FATAL') => SymbolKind::CONSTANT, - strtolower('LIBXML_ERR_ERROR') => SymbolKind::CONSTANT, - strtolower('DDTrace\DBM_PROPAGATION_FULL') => SymbolKind::CONSTANT, - strtolower('DDTrace\Integrations\Exec\proc_get_pid') => SymbolKind::FUNCTION, - ] - ) + $extractor->parseUsedSymbols($extensionSymbols) ); } /** - * @return iterable>>}> + * @return iterable>>, 2?: array}> */ public function provideVariants(): iterable { @@ -68,6 +57,9 @@ public function provideVariants(): iterable yield 'T_STRING issues' => [ __DIR__ . '/data/not-autoloaded/used-symbols/t-string-issues.php', [], + [ + strtolower('PDO') => SymbolKind::CLASSLIKE, + ], ]; yield 'various usages' => [ @@ -160,6 +152,7 @@ public function provideVariants(): iterable 'CURLOPT_SSL_VERIFYHOST' => [19], ], ], + self::extensionSymbolsForExtensionsTestCases(), ]; yield 'extensions global' => [ @@ -183,6 +176,7 @@ public function provideVariants(): iterable 'CURLOPT_SSL_VERIFYHOST' => [19], ], ], + self::extensionSymbolsForExtensionsTestCases(), ]; if (PHP_VERSION_ID >= 80000) { @@ -206,4 +200,22 @@ public function provideVariants(): iterable } } + /** + * @return array + */ + private static function extensionSymbolsForExtensionsTestCases(): array + { + return [ + strtolower('XMLReader') => SymbolKind::CLASSLIKE, + strtolower('PDO') => SymbolKind::CLASSLIKE, + strtolower('json_encode') => SymbolKind::FUNCTION, + strtolower('DDTrace\active_span') => SymbolKind::FUNCTION, + strtolower('DDTrace\root_span') => SymbolKind::FUNCTION, + strtolower('LIBXML_ERR_FATAL') => SymbolKind::CONSTANT, + strtolower('LIBXML_ERR_ERROR') => SymbolKind::CONSTANT, + strtolower('DDTrace\DBM_PROPAGATION_FULL') => SymbolKind::CONSTANT, + strtolower('DDTrace\Integrations\Exec\proc_get_pid') => SymbolKind::FUNCTION, + ]; + } + } diff --git a/tests/data/not-autoloaded/used-symbols/t-string-issues.php b/tests/data/not-autoloaded/used-symbols/t-string-issues.php index 69c8705..68c1595 100644 --- a/tests/data/not-autoloaded/used-symbols/t-string-issues.php +++ b/tests/data/not-autoloaded/used-symbols/t-string-issues.php @@ -1,6 +1,6 @@