fix(extraction): map PHP include/require to file→file dependency edges (#660)
Fixes #660.
Procedural / script-style PHP wires files together with include/require, but codegraph's PHP extractor only captured namespace_use_declaration as an import — so include/require(_once) produced zero file→file dependency edges. callers(lib.php) returned 0 for require_once("lib.php"); impact/trace missed 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
| Before | After | |
|---|---|---|
require_once("lib.php") |
no edge; callers(lib.php) = 0 |
file→file imports edge; callers(lib.php) includes the caller |
require "inc/db.php" (subdir) |
no edge | resolves to inc/db.php |
include $var / require __DIR__.'/x' |
no edge | unchanged — skipped (no static path) |
namespace use App\Foo\Bar |
resolved as before | unchanged |
unresolvable require "inc/db.php" |
— | no edge (never mis-connects to a same-named file elsewhere) |
Validation
npm test on 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)
Note: a full
extraction.test.tsrun hits a pre-existing V8Fatal process out of memory: Zonecrash (~test 205) during turboshaft JIT compilation of the tree-sitter WASM grammars on Node 24.x — reproduced identically on unmodifiedmain, so it is unrelated to this change. The repo'senginesare>=18 <25.
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.ini include_path is not modeled.