Skip to content

Commit

Permalink
Fix another t_string issue
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed Oct 17, 2024
1 parent eaece67 commit 539a00e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/UsedSymbolExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 27 additions & 15 deletions tests/UsedSymbolExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ class UsedSymbolExtractorTest extends TestCase

/**
* @param array<SymbolKind::*, array<string, list<int>>> $expectedUsages
* @param array<string, SymbolKind::*> $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);
Expand All @@ -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<array{string, array<SymbolKind::*, array<string, list<int>>>}>
* @return iterable<array{0: string, 1: array<SymbolKind::*, array<string, list<int>>>, 2?: array<string, SymbolKind::*>}>
*/
public function provideVariants(): iterable
{
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -160,6 +152,7 @@ public function provideVariants(): iterable
'CURLOPT_SSL_VERIFYHOST' => [19],
],
],
self::extensionSymbolsForExtensionsTestCases(),
];

yield 'extensions global' => [
Expand All @@ -183,6 +176,7 @@ public function provideVariants(): iterable
'CURLOPT_SSL_VERIFYHOST' => [19],
],
],
self::extensionSymbolsForExtensionsTestCases(),
];

if (PHP_VERSION_ID >= 80000) {
Expand All @@ -206,4 +200,22 @@ public function provideVariants(): iterable
}
}

/**
* @return array<string, SymbolKind::*>
*/
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,
];
}

}
2 changes: 1 addition & 1 deletion tests/data/not-autoloaded/used-symbols/t-string-issues.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace TString;
namespace PDO;

use function _; // e.g. https://www.php.net/manual/en/function.-.php
use function array_filter;
Expand Down

0 comments on commit 539a00e

Please sign in to comment.