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

Function phpAppendedPath

src/extraction/languages/php.ts:146–156  ·  view source on GitHub ↗

* The path that string literals (and `DIRECTORY_SEPARATOR`, read as `/`) * append to a directory: it starts with `/`, names a file rather than a * directory (no trailing `/`), and has no empty segment. Null when anything * else is appended.

(tail: SyntaxNode[], source: string)

Source from the content-addressed store, hash-verified

144 * else is appended.
145 */
146function phpAppendedPath(tail: SyntaxNode[], source: string): string | null {
147 let rest = '';
148 for (const part of tail) {
149 const literal = phpLiteralText(part, source);
150 if (literal !== null) rest += literal;
151 else if (getNodeText(part, source).replace(/^\\/, '') === 'DIRECTORY_SEPARATOR') rest += '/';
152 else return null;
153 }
154 if (!rest.startsWith('/') || rest.endsWith('/')) return null;
155 return rest.split('/').slice(1).every((seg) => seg !== '') ? rest : null;
156}
157
158/**
159 * `__DIR__ . '/inc/a.php'`, `dirname(__FILE__) . DIRECTORY_SEPARATOR . 'a.php'`:

Callers 1

phpDirectoryIncludePathFunction · 0.85

Calls 2

getNodeTextFunction · 0.90
phpLiteralTextFunction · 0.85

Tested by

no test coverage detected