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

Function phpStaticIncludePath

src/extraction/languages/php.ts:33–41  ·  view source on GitHub ↗

* Extract a static path from a PHP include/require expression: a string * literal, or one appended to the including file's own directory or to the * web server's root (#3298). * * Returns null for dynamic forms (`include $var`, interpolated strings, * `$base . '/x'`): they have no resolvable co

(node: SyntaxNode, source: string)

Source from the content-addressed store, hash-verified

31 * `$base . '/x'`): they have no resolvable compile-time path.
32 */
33function phpStaticIncludePath(node: SyntaxNode, source: string): string | null {
34 // The path argument is the expression's first named child; the call-style
35 // form `require("x")` wraps it in a parenthesized_expression.
36 let arg: SyntaxNode | null = node.namedChild(0);
37 if (arg?.type === 'parenthesized_expression') arg = arg.namedChild(0);
38 if (!arg) return null;
39 if (arg.type === 'binary_expression') return phpDirectoryIncludePath(arg, source);
40 return phpLiteralText(arg, source);
41}
42
43/** The text of a pure string literal (no interpolation or escapes), else null. */
44function phpLiteralText(arg: SyntaxNode, source: string): string | null {

Callers 1

php.tsFile · 0.85

Calls 2

phpDirectoryIncludePathFunction · 0.85
phpLiteralTextFunction · 0.85

Tested by

no test coverage detected