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

Method extract_call

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

Source from the content-addressed store, hash-verified

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

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