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

Function phpDirectoryIncludePath

src/extraction/languages/php.ts:169–187  ·  view source on GitHub ↗

* `__DIR__ . '/inc/a.php'`, `dirname(__FILE__) . DIRECTORY_SEPARATOR . 'a.php'`: * a path appended to the including file's directory (see * phpAppendedPath), read as a path relative to it (`./inc/a.php`, * `../config/a.php`), which the resolver loads exactly as written, as PHP * does. Nu

(expr: SyntaxNode, source: string)

Source from the content-addressed store, hash-verified

167 * server's root instead, written behind {@link PHP_DOCUMENT_ROOT}.
168 */
169function phpDirectoryIncludePath(expr: SyntaxNode, source: string): string | null {
170 const [head, ...tail] = phpConcatParts(expr, source);
171 if (!head || tail.length === 0) return null;
172 if (phpIsDocumentRoot(head, source)) {
173 const rest = phpAppendedPath(tail, source);
174 return rest === null ? null : PHP_DOCUMENT_ROOT + rest;
175 }
176 const dir = PHP_OWN_DIRECTORY.exec(getNodeText(head, source).replace(/\s+/g, ''));
177 if (!dir) return null;
178 const qualified = getNodeText(head, source).trimStart().startsWith('\\');
179 if (dir[1] !== undefined && !qualified && phpShadowsDirname(expr, source)) return null;
180 const rest = phpAppendedPath(tail, source);
181 if (rest === null) return null;
182 // __DIR__ and dirname(__FILE__) are the file's directory; dirname(__DIR__)
183 // is one up; a levels argument climbs that many from __FILE__ (one more from __DIR__).
184 const levels = dir[1] === undefined ? 1 : Number(dir[2] ?? '1') + (dir[1].toUpperCase() === '__DIR__' ? 1 : 0);
185 if (levels > 16) return null;
186 return `${levels === 1 ? './' : '../'.repeat(levels - 1)}${rest.slice(1)}`;
187}
188
189/** PHP built-in return types that can't be a method receiver (so no class to chain on). */
190const PHP_NON_CLASS_RETURN = new Set([

Callers 1

phpStaticIncludePathFunction · 0.85

Calls 7

getNodeTextFunction · 0.90
phpConcatPartsFunction · 0.85
phpIsDocumentRootFunction · 0.85
phpAppendedPathFunction · 0.85
phpShadowsDirnameFunction · 0.85
NumberInterface · 0.85
execMethod · 0.65

Tested by

no test coverage detected