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

Function phpLiteralText

src/extraction/languages/php.ts:44–52  ·  view source on GitHub ↗

The text of a pure string literal (no interpolation or escapes), else null.

(arg: SyntaxNode, source: string)

Source from the content-addressed store, hash-verified

42
43/** The text of a pure string literal (no interpolation or escapes), else null. */
44function phpLiteralText(arg: SyntaxNode, source: string): string | null {
45 if (arg.type !== 'string' && arg.type !== 'encapsed_string') return null;
46 // Pure literal only: any non-`string_content` child (interpolated variable,
47 // escape sequence, …) means the value isn't a static path.
48 const parts = arg.namedChildren;
49 if (parts.some((c: SyntaxNode) => c.type !== 'string_content')) return null;
50 const content = parts.find((c: SyntaxNode) => c.type === 'string_content');
51 return content ? getNodeText(content, source) : null;
52}
53
54/**
55 * `__DIR__`, `dirname(__FILE__)`, `\\dirname(__DIR__)`, `dirname(__FILE__, 2)`

Callers 3

phpStaticIncludePathFunction · 0.85
phpIsDocumentRootFunction · 0.85
phpAppendedPathFunction · 0.85

Calls 1

getNodeTextFunction · 0.90

Tested by

no test coverage detected