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

Function php_lookup_method

internal/cbm/lsp/php_lsp.c:350–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348/* ── method lookup with parent walk ─────────────────────────────── */
349
350const CBMRegisteredFunc *php_lookup_method(PHPLSPContext *ctx, const char *class_qn,
351 const char *method_name) {
352 if (!class_qn || !method_name)
353 return NULL;
354
355 /* Direct lookup by the registry's receiver_qn -> method_name index. */
356 const CBMRegisteredFunc *f = cbm_registry_lookup_method(ctx->registry, class_qn, method_name);
357 if (f)
358 return f;
359
360 /* If the QN we have isn't the registry's canonical key, resolve the
361 * type to its registered identity and retry. */
362 const CBMRegisteredType *t = cbm_registry_lookup_type(ctx->registry, class_qn);
363 if (!t)
364 t = lookup_type_with_project(ctx, class_qn);
365 if (!t)
366 return NULL;
367 if (strcmp(t->qualified_name, class_qn) != 0) {
368 f = cbm_registry_lookup_method(ctx->registry, t->qualified_name, method_name);
369 if (f)
370 return f;
371 }
372
373 /* Walk the full ancestor chain. PHP only allows single inheritance for
374 * `extends`, but a class may also pick up methods from `implements` /
375 * traits, both of which are recorded in embedded_types. We iterate
376 * across all entries and recurse into each branch with cycle-detection.
377 *
378 * Cap depth at 16 across all visited types to bound runtime. */
379 const char *visited[32];
380 int visited_count = 0;
381 const char *frontier[32];
382 int frontier_count = 0;
383 if (t->embedded_types) {
384 for (int i = 0; t->embedded_types[i] && frontier_count < 32; i++) {
385 frontier[frontier_count++] = t->embedded_types[i];
386 }
387 }
388 while (frontier_count > 0 && visited_count < 32) {
389 const char *parent = frontier[--frontier_count];
390 bool seen = false;
391 for (int v = 0; v < visited_count; v++) {
392 if (strcmp(visited[v], parent) == 0) {
393 seen = true;
394 break;
395 }
396 }
397 if (seen)
398 continue;
399 visited[visited_count++] = parent;
400
401 f = cbm_registry_lookup_method(ctx->registry, parent, method_name);
402 if (f)
403 return f;
404
405 const CBMRegisteredType *next = cbm_registry_lookup_type(ctx->registry, parent);
406 if (!next)
407 next = lookup_type_with_project(ctx, parent);

Callers 7

class_has_magic_callFunction · 0.85
php_eval_expr_typeFunction · 0.85
eval_member_call_typeFunction · 0.85
process_foreachFunction · 0.85
resolve_function_callFunction · 0.85
resolve_member_callFunction · 0.85
resolve_static_callFunction · 0.85

Calls 4

cbm_registry_lookup_typeFunction · 0.85
lookup_type_with_projectFunction · 0.85
cbm_registry_lookup_funcFunction · 0.85

Tested by

no test coverage detected