fix(extraction): map PHP include/require to file→file dependency edges (#660)#663
Open
maxmilian wants to merge 1 commit into
Open
fix(extraction): map PHP include/require to file→file dependency edges (#660)#663maxmilian wants to merge 1 commit into
maxmilian wants to merge 1 commit into
Conversation
colbymchenry#660) PHP's importTypes only captured namespace_use_declaration, so include/require(_once) — the dependency mechanism in procedural and script-style PHP — never produced edges. callers, impact, and trace missed the entire file-include graph; only namespace `use` became a dependency edge. Capture the four include/require expression types and emit file→file imports edges, reusing the path-based resolution that C/C++ #include already goes through. Only static string-literal paths are resolved (relative to the including file); dynamic forms (include $var, require __DIR__ . '/x', interpolated strings) are skipped. Include PATHS are distinguished from namespace `use` symbols by shape: a path contains '/' or '.', which PHP identifiers and FQNs never do. A path-shaped include that doesn't resolve to a known project file is left unresolved and does NOT fall back to the symbol name-matcher, which would otherwise mis-connect "inc/db.php" to an unrelated db.php elsewhere — a wrong edge is worse than a missing one. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
909cc42 to
b4bed16
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #660.
Procedural / script-style PHP wires files together with
include/require, but codegraph's PHP extractor only capturednamespace_use_declarationas an import — soinclude/require(_once) produced zero file→file dependency edges.callers(lib.php)returned 0 forrequire_once("lib.php");impact/tracemissed the whole file-include graph.What changed
src/extraction/languages/php.ts(+41): captureinclude/include_once/require/require_onceexpressions and extract the static string-literal path (single/double quotes, with/without parens). Dynamic forms (include $var,require __DIR__ . '/x', interpolated strings) resolve to null and are skipped.src/resolution/import-resolver.ts(+71): resolve a PHP include path to a file→fileimportsedge relative to the including file, mirroring the existing C/C++#includepath. AddedisPhpIncludePathRefto distinguish include paths (contain/or.) from namespaceusesymbols (FQN / bare class — which never do).src/resolution/index.ts(+14): a path-shaped include that doesn't resolve to a known project file is left unresolved and does not fall back to the symbol name-matcher (which would otherwise mis-connectinc/db.phpto an unrelateddb.phpelsewhere).Before / After
require_once("lib.php")callers(lib.php)= 0importsedge;callers(lib.php)includes the callerrequire "inc/db.php"(subdir)inc/db.phpinclude $var/require __DIR__.'/x'use App\Foo\Barrequire "inc/db.php"Validation
npm teston the changed suites (Node 24.14.0):npx vitest run __tests__/resolution.test.ts— 56/56 passing (+4 new: include→file e2e, subdirectory resolution, no-mis-connect regression,isPhpIncludePathRefunit test)npx vitest run __tests__/extraction.test.ts -t "#660"— 3/3 new extraction tests passing (four include/require forms, dynamic-skip, include + namespace-use coexistence)Scope
PHP-only — other languages' extractors and resolvers are untouched (the new resolution branch is gated on
language === 'php'). Static literal paths only, matching the issue scope; php.iniinclude_pathis not modeled.