MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / normalize_fn_ref_value

Method normalize_fn_ref_value

codegraph-kernel/src/php.rs:1264–1325  ·  view source on GitHub ↗
(&mut self, v: Node<'t>, from: u32, depth: u32)

Source from the content-addressed store, hash-verified

1262 }
1263
1264 fn normalize_fn_ref_value(&mut self, v: Node<'t>, from: u32, depth: u32) {
1265 stack_guard!();
1266 if depth > 4 {
1267 return;
1268 }
1269 match v.kind() {
1270 "argument" => {
1271 for i in 0..v.named_child_count() {
1272 if let Some(c) = v.named_child(i) {
1273 self.normalize_fn_ref_value(c, from, depth + 1);
1274 }
1275 }
1276 }
1277 // String callable — trustworthy ONLY as an argument to a known
1278 // callable-taking core function; skipGate (resolution's
1279 // unique-or-drop rule takes over). Namespaced strings drop.
1280 "string" | "encapsed_string" => {
1281 let Some(callee) = php_enclosing_call_name(v).map(|f| self.text(f)) else {
1282 return;
1283 };
1284 if !is_php_callable_hof(callee) {
1285 return;
1286 }
1287 let Some(content) = self.php_string_content(v) else { return };
1288 if simple_callable_re().is_match(&content) || qualified_callable_re().is_match(&content)
1289 {
1290 self.push_fn_ref_cand(from, &content, v, true);
1291 }
1292 }
1293 // Array callables in ANY call's arguments: `[$this, 'm']` →
1294 // this.m; `[Foo::class, 'm']` → Foo::m; `['Cls', 'm']` → nothing.
1295 "array_creation_expression" => {
1296 if v.named_child_count() != 2 {
1297 return;
1298 }
1299 let recv = v.named_child(0).and_then(|e| e.named_child(0));
1300 let str_el = v.named_child(1).and_then(|e| e.named_child(0));
1301 let (Some(recv), Some(str_el)) = (recv, str_el) else { return };
1302 if !matches!(str_el.kind(), "encapsed_string" | "string") {
1303 return;
1304 }
1305 let Some(member) = self.php_string_content(str_el) else { return };
1306 if !simple_callable_re().is_match(&member) {
1307 return;
1308 }
1309 if recv.kind() == "variable_name" && self.text(recv) == "$this" {
1310 let name = format!("this.{member}");
1311 self.push_fn_ref_cand(from, &name, str_el, false);
1312 } else if recv.kind() == "class_constant_access_expression" {
1313 let cls = recv.named_child(0);
1314 let kw = recv.named_child(1);
1315 if let (Some(cls), Some(kw)) = (cls, kw) {
1316 if self.text(kw) == "class" {
1317 let name = format!("{}::{member}", self.text(cls));
1318 self.push_fn_ref_cand(from, &name, str_el, false);
1319 }
1320 }
1321 }

Callers 1

maybe_capture_fn_refsMethod · 0.45

Calls 8

php_enclosing_call_nameFunction · 0.85
is_php_callable_hofFunction · 0.85
simple_callable_reFunction · 0.85
qualified_callable_reFunction · 0.85
mapMethod · 0.80
php_string_contentMethod · 0.80
textMethod · 0.65
push_fn_ref_candMethod · 0.45

Tested by

no test coverage detected