Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
fix(php): scope use-clause parsing to the clause, not the statement
KageBinary5c322a990190
diff --git a/core-ingestion/src/__tests__/resolveEdges.test.ts b/core-ingestion/src/__tests__/resolveEdges.test.tsindex 6de0405a..076ea204 100644--- a/core-ingestion/src/__tests__/resolveEdges.test.ts+++ b/core-ingestion/src/__tests__/resolveEdges.test.ts@@ -294,6 +294,69 @@ class User { public function save(): void {} }expect(edges).toHaveLength(3);});+ it('does not emit a phantom import for a PHP alias name', () => {+ // The alias is a sibling (name) of the (qualified_name) inside the clause,+ // so an unanchored capture treated `Admin` as a second imported module and+ // matched it against an unrelated class of that name.+ const consumer = parseFile(+ '/repo/Consumer.php',+ `<?php+use Vendor\\Package\\User as Admin;+function run(Admin $a): void { new Admin(); $a->save(); }+ `,+ )!;+ const unrelated = parseFile(+ '/repo/Admin.php',+ '<?php class Admin { public function save(): void {} }',+ )!;+ const intended = parseFile(+ '/repo/Vendor/Package/User.php',+ '<?php namespace Vendor\\Package; class User { public function save(): void {} }',+ )!;++ const edges = resolveEdges([consumer, unrelated, intended]);++ expect(+ edges.filter(+ (edge) => edge.predicate === 'IMPORTS' && edge.dstFilePath === '/repo/Admin.php',+ ),+ ).toEqual([]);+ expect(+ edges.filter((edge) => edge.dstFilePath === '/repo/Admin.php' && edge.confidence === 0.9),+ ).toEqual([]);+ });++ it('resolves an un-aliased clause in a comma-separated PHP use statement', () => {+ // `importAliased` was derived from the whole statement, so one alias+ // anywhere in the list disabled FQCN resolution for every clause.+ const consumer = parseFile(+ '/repo/Consumer.php',+ `<?php+use Vendor\\One\\Alpha, Vendor\\Two\\Beta as Bee;+function run(Alpha $a): void { new Alpha(); }+ `,+ )!;+ const intended = parseFile(+ '/repo/Vendor/One/Alpha.php',+ '<?php namespace Vendor\\One; class Alpha {}',+ )!;+ const decoy = parseFile(+ '/repo/Other/Alpha.php',+ '<?php namespace Other\\Place; class Alpha {}',+ )!;++ const edges = resolveEdges([consumer, intended, decoy]);++ expect(+ edges.filter(+ (edge) => edge.predicate === 'IMPORTS'+ && edge.dstFilePath === '/repo/Vendor/One/Alpha.php'+ && edge.confidence === 0.9,+ ),+ ).toHaveLength(1);+ expect(edges.filter((edge) => edge.dstFilePath === '/repo/Other/Alpha.php')).toEqual([]);+ });+it('resolves PHP class imports, references, and calls by exact FQCN', () => {const consumer = parseFile('/repo/Consumer.php',diff --git a/core-ingestion/src/index.ts b/core-ingestion/src/index.tsindex 5ee6b342..e7603d86 100644--- a/core-ingestion/src/index.ts+++ b/core-ingestion/src/index.ts@@ -2489,6 +2489,15 @@ export function parseFile(filePath: string, source: string): FileParseResult | n? 'const' as const: undefined: undefined;+ // Alias detection is per *clause*, not per statement. `use A\B, C\D as E;`+ // is one declaration with two clauses, so testing the statement text+ // flagged the un-aliased clause too and silently disabled FQCN+ // resolution for it. Reading the node also drops an unanchored+ // /\s+as\s+/ over repo-controlled text, which backtracks quadratically.+ const phpUseClause = importSource.node.parent;+ const phpImportAliased = language === SupportedLanguages.PHP+ && phpUseClause?.type === 'namespace_use_clause'+ && phpUseClause.namedChildCount > 1;entities.push({ name: modName, kind: 'module', lineStart: importSource.node.startPosition.row + 1, lineEnd: importSource.node.startPosition.row + 1, language });relationships.push({srcName: fileName,@@ -2496,9 +2505,7 @@ export function parseFile(filePath: string, source: string): FileParseResult | npredicate: 'IMPORTS',importRaw,...(importKind ? { importKind } : {}),- ...(language === SupportedLanguages.PHP && /\s+as\s+/i.test(phpImportText)- ? { importAliased: true }- : {}),+ ...(phpImportAliased ? { importAliased: true } : {}),});}continue;diff --git a/core-ingestion/src/queries.ts b/core-ingestion/src/queries.tsindex 33e516f9..a98aebc8 100644--- a/core-ingestion/src/queries.ts+++ b/core-ingestion/src/queries.ts@@ -1026,9 +1026,13 @@ export const PHP_QUERIES = `; ── Imports: use statements ──────────────────────────────────────────────────; Simple: use App\\Models\\User;+; The leading anchor pins the capture to the clause's FIRST named child. In+; "use A\\B\\C as Alias" the alias is a sibling (name) of the (qualified_name),+; so an unanchored alternation would capture it too and emit a phantom import+; of Alias. "use GlobalThing;" is a lone (name) child and still matches.(namespace_use_declaration(namespace_use_clause- [(qualified_name) (name)] @import.source)) @import+ . [(qualified_name) (name)] @import.source)) @import; ── Function/method calls ────────────────────────────────────────────────────; Regular function call: foo()