MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolvePhpIncludePath

Function resolvePhpIncludePath

src/resolution/import-resolver.ts:741–756  ·  view source on GitHub ↗

* Resolve a PHP include/require path to a project-relative file path. * * PHP resolves includes relative to the including file's directory (the * common case for procedural codebases); php.ini `include_path` is not * modeled. Callers pass an already-extracted static literal path.

(
  includePath: string,
  fromFile: string,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

739 * modeled. Callers pass an already-extracted static literal path.
740 */
741function resolvePhpIncludePath(
742 includePath: string,
743 fromFile: string,
744 context: ResolutionContext
745): string | null {
746 const projectRoot = context.getProjectRoot();
747 const fromDir = path.dirname(path.join(projectRoot, fromFile));
748 const basePath = path.resolve(fromDir, includePath);
749 const relativePath = path.relative(projectRoot, basePath).replace(/\\/g, '/');
750 if (context.fileExists(relativePath)) return relativePath;
751 // The literal may omit the .php extension (e.g. include "config").
752 for (const ext of EXTENSION_RESOLUTION.php ?? []) {
753 if (context.fileExists(relativePath + ext)) return relativePath + ext;
754 }
755 return null;
756}
757
758/**
759 * Extract import mappings from a file

Callers 1

resolveViaImportFunction · 0.85

Calls 4

fileExistsMethod · 0.80
getProjectRootMethod · 0.65
resolveMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected