MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / php_qualify_class

Function php_qualify_class

internal/cbm/extract_calls.c:3026–3047  ·  view source on GitHub ↗

Qualify a class name the way PHP resolves it: a leading '\' is already * absolute; a first segment that a `use` clause imports (by alias or by last * segment) is replaced by the imported name; anything else is relative to the * file's namespace. Imports and the namespace are extracted before the call * walk, so both are complete here. */

Source from the content-addressed store, hash-verified

3024 * file's namespace. Imports and the namespace are extracted before the call
3025 * walk, so both are complete here. */
3026static const char *php_qualify_class(CBMExtractCtx *ctx, const char *written) {
3027 if (written[0] == '\\') {
3028 return written + SKIP_ONE;
3029 }
3030 const char *sep = strchr(written, '\\');
3031 size_t first_len = sep ? (size_t)(sep - written) : strlen(written);
3032 const CBMImportArray *imps = &ctx->result->imports;
3033 for (int i = 0; i < imps->count; i++) {
3034 const CBMImport *imp = &imps->items[i];
3035 const char *path = imp->module_path;
3036 if (!imp->local_name || !path || strlen(imp->local_name) != first_len ||
3037 strncmp(imp->local_name, written, first_len) != 0) {
3038 continue;
3039 }
3040 path += path[0] == '\\' ? SKIP_ONE : 0;
3041 if (php_is_class_path(path)) {
3042 return cbm_arena_sprintf(ctx->arena, "%s%s", path, sep ? sep : "");
3043 }
3044 }
3045 const char *ns = ctx->result->namespace_name;
3046 return ns && ns[0] ? cbm_arena_sprintf(ctx->arena, "%s\\%s", ns, written) : written;
3047}
3048
3049/* The fully-qualified class a PHP `X::class` expression names (`use` imports
3050 * and the file namespace applied). NULL for any other expression, including

Callers 1

php_class_literal_fqnFunction · 0.85

Calls 2

php_is_class_pathFunction · 0.85
cbm_arena_sprintfFunction · 0.70

Tested by

no test coverage detected