| 2584 | } |
| 2585 | |
| 2586 | static void process_function_like(PHPLSPContext *ctx, TSNode node) { |
| 2587 | const char *kind = ts_node_type(node); |
| 2588 | bool is_method = (strcmp(kind, "method_declaration") == 0); |
| 2589 | bool is_named = is_method || (strcmp(kind, "function_definition") == 0) || |
| 2590 | (strcmp(kind, "function_static_declaration") == 0); |
| 2591 | |
| 2592 | /* Save context. */ |
| 2593 | CBMScope *saved_scope = ctx->current_scope; |
| 2594 | const char *saved_func = ctx->enclosing_func_qn; |
| 2595 | |
| 2596 | ctx->current_scope = cbm_scope_push(ctx->arena, ctx->current_scope); |
| 2597 | |
| 2598 | /* Determine func QN. Mirror what the unified extractor produces: classes |
| 2599 | * and free functions are namespaced by file module_qn, NOT the PHP |
| 2600 | * namespace declaration (the unified extractor ignores `namespace`). |
| 2601 | * Method QN = enclosing_class_qn + "." + method_name. Free function QN = |
| 2602 | * module_qn + "." + name. */ |
| 2603 | if (is_named) { |
| 2604 | TSNode name_node = ts_node_child_by_field_name(node, "name", 4); |
| 2605 | if (!ts_node_is_null(name_node)) { |
| 2606 | char *fname = php_node_text(ctx, name_node); |
| 2607 | if (fname) { |
| 2608 | if (is_method && ctx->enclosing_class_qn) { |
| 2609 | ctx->enclosing_func_qn = |
| 2610 | cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->enclosing_class_qn, fname); |
| 2611 | } else if (ctx->module_qn) { |
| 2612 | ctx->enclosing_func_qn = |
| 2613 | cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->module_qn, fname); |
| 2614 | } else { |
| 2615 | ctx->enclosing_func_qn = cbm_arena_strdup(ctx->arena, fname); |
| 2616 | } |
| 2617 | } |
| 2618 | } |
| 2619 | } |
| 2620 | |
| 2621 | /* Parameters. */ |
| 2622 | TSNode params = ts_node_child_by_field_name(node, "parameters", 10); |
| 2623 | bind_typed_parameters(ctx, params); |
| 2624 | |
| 2625 | /* Closure `use ($a, $b)` clause: copy captured-variable types from the |
| 2626 | * parent scope into the closure scope. tree-sitter-php emits an |
| 2627 | * `anonymous_function_use_clause` child of `anonymous_function`. */ |
| 2628 | if (strcmp(kind, "anonymous_function") == 0) { |
| 2629 | uint32_t fnc = ts_node_child_count(node); |
| 2630 | for (uint32_t i = 0; i < fnc; i++) { |
| 2631 | TSNode c = ts_node_child(node, i); |
| 2632 | if (ts_node_is_null(c) || !ts_node_is_named(c)) |
| 2633 | continue; |
| 2634 | if (strcmp(ts_node_type(c), "anonymous_function_use_clause") != 0) |
| 2635 | continue; |
| 2636 | uint32_t unc = ts_node_child_count(c); |
| 2637 | for (uint32_t j = 0; j < unc; j++) { |
| 2638 | TSNode v = ts_node_child(c, j); |
| 2639 | if (ts_node_is_null(v) || !ts_node_is_named(v)) |
| 2640 | continue; |
| 2641 | if (strcmp(ts_node_type(v), "variable_name") != 0) |
| 2642 | continue; |
| 2643 | char *vt = php_node_text(ctx, v); |
no test coverage detected