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

Method extract_call

codegraph-kernel/src/php.rs:1157–1223  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

1155 // --- calls ---------------------------------------------------------------------
1156
1157 fn extract_call(&mut self, node: Node<'t>) {
1158 if self.stack.is_empty() {
1159 return;
1160 }
1161 let caller = self.top_row();
1162 let mut callee_name = String::new();
1163
1164 let name_field = node.child_by_field_name("name");
1165 let object_field = node
1166 .child_by_field_name("object")
1167 .or_else(|| node.child_by_field_name("scope"));
1168
1169 if let (Some(name_field), Some(object_field)) = (name_field, object_field) {
1170 // member_call_expression / scoped_call_expression.
1171 let method_name = self.text(name_field);
1172
1173 // Fluent static-factory `Cls::factory($x)->method()` — encode
1174 // `Cls::factory().method` (inner args dropped) and return; the
1175 // inner scoped call is also visited by recursion (`Cls.factory`).
1176 if !method_name.is_empty() && object_field.kind() == "scoped_call_expression" {
1177 let inner_scope = object_field.child_by_field_name("scope");
1178 let inner_name = object_field.child_by_field_name("name");
1179 let callee = match (inner_scope, inner_name) {
1180 (Some(s), Some(n)) => {
1181 format!("{}::{}().{method_name}", self.text(s), self.text(n))
1182 }
1183 _ => method_name.to_string(),
1184 };
1185 if !callee.is_empty() {
1186 self.push_ref_at(caller, &callee, edge_kind_index("calls").unwrap(), node);
1187 }
1188 return;
1189 }
1190
1191 // receiverName = raw receiver text with ONE leading `$` stripped:
1192 // `$this->prop->m()` → `this->prop.m` (#1251 encoding — the whole
1193 // resolution machinery is TS-side); chains keep args
1194 // (`this->factory($cfg).m`); literals are NOT suppressed
1195 // (`"chain".upper`); scoped calls are DOT-joined (`UserModel.query`).
1196 let receiver_raw = self.text(object_field);
1197 let receiver = receiver_raw.strip_prefix('$').unwrap_or(receiver_raw);
1198 if !method_name.is_empty() {
1199 if matches!(receiver, "self" | "this" | "cls" | "super" | "parent" | "static") {
1200 callee_name = method_name.to_string();
1201 } else {
1202 callee_name = format!("{receiver}.{method_name}");
1203 }
1204 }
1205 } else {
1206 // function_call_expression: raw func text — bare `helper`,
1207 // qualified `\App\Helpers\format_id` verbatim, `$fn` for
1208 // variable callees, FCC `f(...)` → `f`.
1209 let func = node
1210 .child_by_field_name("function")
1211 .or_else(|| node.named_child(0));
1212 if let Some(func) = func {
1213 callee_name = self.text(func).to_string();
1214 }

Callers 2

visit_nodeMethod · 0.45

Calls 5

edge_kind_indexFunction · 0.85
textMethod · 0.65
unwrapMethod · 0.60
top_rowMethod · 0.45
push_ref_atMethod · 0.45

Tested by

no test coverage detected