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

Function resolve_php_declared_use

src/pipeline/pass_pkgmap.c:2703–2734  ·  view source on GitHub ↗

Resolve a PHP namespaced `use` that no psr-4 prefix covers, through the * namespaces project files DECLARE. `use A\B\C` names C in namespace A\B (or * the namespace A\B\C itself, as an alias): the target is the A\B file that * defines C, else a file declaring namespace A\B\C, else the first A\B file. * A namespace no project PHP file declares (Illuminate\, Spatie\, ...) is * outside the proje

Source from the content-addressed store, hash-verified

2701 * outside the project: the import stays unresolved instead of binding by name
2702 * to a same-named project symbol, possibly in another language. */
2703static const cbm_gbuf_node_t *resolve_php_declared_use(const cbm_pipeline_ctx_t *ctx,
2704 const char *source_file_qn,
2705 const CBMImport *imp,
2706 CBMHashTable *namespace_map) {
2707 const char *name = imp->module_path[0] == '\\' ? imp->module_path + SKIP_ONE : imp->module_path;
2708 char key[CBM_SZ_1K];
2709 if (strlen(name) >= sizeof(key)) {
2710 return NULL;
2711 }
2712 snprintf(key, sizeof(key), "%s", name);
2713 for (char *p = key; *p; p++) {
2714 if (*p == '\\') {
2715 *p = '.';
2716 }
2717 }
2718 const char *full_bucket = (const char *)cbm_ht_get(namespace_map, key);
2719 char *dot = strrchr(key, '.');
2720 *dot = '\0'; /* PHP_USE_NAMESPACED guarantees a separator */
2721 const char *parent_bucket = (const char *)cbm_ht_get(namespace_map, key);
2722 const char *leaf = dot + SKIP_ONE;
2723
2724 const cbm_gbuf_node_t *hit = php_bucket_declaring(ctx, parent_bucket, source_file_qn, leaf);
2725 if (!hit) {
2726 const char *cursor = full_bucket;
2727 hit = php_bucket_next(ctx, &cursor, source_file_qn);
2728 }
2729 if (!hit) {
2730 const char *cursor = parent_bucket;
2731 hit = php_bucket_next(ctx, &cursor, source_file_qn);
2732 }
2733 return hit;
2734}
2735
2736const cbm_gbuf_node_t *cbm_pipeline_resolve_import_node(const cbm_pipeline_ctx_t *ctx,
2737 const char *source_rel,

Callers 1

Calls 3

cbm_ht_getFunction · 0.85
php_bucket_declaringFunction · 0.85
php_bucket_nextFunction · 0.85

Tested by

no test coverage detected