(&mut self, v: Node<'t>, from: u32, depth: u32)
| 1419 | } |
| 1420 | |
| 1421 | fn normalize_fn_ref_value(&mut self, v: Node<'t>, from: u32, depth: u32) { |
| 1422 | stack_guard!(); |
| 1423 | if depth > 4 { |
| 1424 | return; |
| 1425 | } |
| 1426 | match v.kind() { |
| 1427 | "argument" => { |
| 1428 | for i in 0..v.named_child_count() { |
| 1429 | if let Some(c) = v.named_child(i) { |
| 1430 | self.normalize_fn_ref_value(c, from, depth + 1); |
| 1431 | } |
| 1432 | } |
| 1433 | } |
| 1434 | // String callable — trustworthy ONLY as an argument to a known |
| 1435 | // callable-taking core function; skipGate (resolution's |
| 1436 | // unique-or-drop rule takes over). Namespaced strings drop. |
| 1437 | "string" | "encapsed_string" => { |
| 1438 | let Some(callee) = php_enclosing_call_name(v).map(|f| self.text(f)) else { |
| 1439 | return; |
| 1440 | }; |
| 1441 | if !is_php_callable_hof(callee) { |
| 1442 | return; |
| 1443 | } |
| 1444 | let Some(content) = self.php_string_content(v) else { return }; |
| 1445 | if simple_callable_re().is_match(&content) || qualified_callable_re().is_match(&content) |
| 1446 | { |
| 1447 | self.push_fn_ref_cand(from, &content, v, true); |
| 1448 | } |
| 1449 | } |
| 1450 | // Array callables in ANY call's arguments: `[$this, 'm']` → |
| 1451 | // this.m; `[Foo::class, 'm']` → Foo::m; `['Cls', 'm']` → nothing. |
| 1452 | "array_creation_expression" => { |
| 1453 | if v.named_child_count() != 2 { |
| 1454 | return; |
| 1455 | } |
| 1456 | let recv = v.named_child(0).and_then(|e| e.named_child(0)); |
| 1457 | let str_el = v.named_child(1).and_then(|e| e.named_child(0)); |
| 1458 | let (Some(recv), Some(str_el)) = (recv, str_el) else { return }; |
| 1459 | if !matches!(str_el.kind(), "encapsed_string" | "string") { |
| 1460 | return; |
| 1461 | } |
| 1462 | let Some(member) = self.php_string_content(str_el) else { return }; |
| 1463 | if !simple_callable_re().is_match(&member) { |
| 1464 | return; |
| 1465 | } |
| 1466 | if recv.kind() == "variable_name" && self.text(recv) == "$this" { |
| 1467 | let name = format!("this.{member}"); |
| 1468 | self.push_fn_ref_cand(from, &name, str_el, false); |
| 1469 | } else if recv.kind() == "class_constant_access_expression" { |
| 1470 | let cls = recv.named_child(0); |
| 1471 | let kw = recv.named_child(1); |
| 1472 | if let (Some(cls), Some(kw)) = (cls, kw) { |
| 1473 | if self.text(kw) == "class" { |
| 1474 | let name = format!("{}::{member}", self.text(cls)); |
| 1475 | self.push_fn_ref_cand(from, &name, str_el, false); |
| 1476 | } |
| 1477 | } |
| 1478 | } |
no test coverage detected