From 02c896e401fcb63e398cce1b12a2bea9cbf17f26 Mon Sep 17 00:00:00 2001 From: Andrey Vasilevsky Date: Sat, 7 Nov 2026 19:04:42 -0800 Subject: [PATCH 1/2] fix(php): resolve calls to the receiver's class, not any same-named method (#31) PHP methods were stored and called by their bare name, so two classes' `render` were one symbol to the resolver: a call to Repro\Alpha\Screen::render resolved to whichever `render` was most complex, and the callers fallback then borrowed the other class's callers. Explicit global calls kept their leading backslash and never matched, and file-scope calls were dropped. PHP extraction - Methods are keyed `Namespace\Class::method` (display name unchanged) and stored with a qualified_name; methods are linked to their class. - A method call is qualified only when its receiver's class is certain: $this/self/static/parent, `new X()`, typed parameters, `$x = new X()` (a variable seen with two classes is unknown), typed and promoted properties. Class names follow PHP rules: leading `\`, imports including group uses and aliases, then the current namespace. - `\foo()` and `\A\foo()` drop the leading backslash; `use function` aliases apply; unqualified calls keep their bare name (PHP's runtime namespace fallback). - Calls outside any function are made by the file node. - Group-use imports keep their prefix (`use A\{B}` imports `A\B`). Shared resolver - Prefer an exact qualified_name match; follow `inherits` (traits, parent, interfaces) for `Class::method` the class does not declare. - A bare name shared by several functions, at least one a method, is left unresolved instead of guessed. Multi-arch copies of one free function still resolve as before. - Unresolved calls on file nodes are resolved too. - The callers same-name fallback only treats the same symbol as a variant (same owning class and qualified name), never another class's method. The reporter's fixture now gives the expected answer for every query. Measured cross-file call edges: monolog 1,604 -> 1,667; gson 14 -> 7 (the 7 were bare Java method names shared by several classes, previously assigned to the most complex one); a Python project unchanged at 451. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017rVbt7rENTwXkdHt3Bpgb5 --- crates/codegraph-php/src/extractor.rs | 8 +- crates/codegraph-php/src/mapper.rs | 157 +++--- crates/codegraph-php/src/visitor.rs | 503 ++++++++++++++++-- crates/codegraph-server/src/domain/callers.rs | 55 ++ crates/codegraph-server/src/watcher.rs | 295 +++++++++- 5 files changed, 868 insertions(+), 150 deletions(-) diff --git a/crates/codegraph-php/src/extractor.rs b/crates/codegraph-php/src/extractor.rs index 7afacbc..52c228f 100644 --- a/crates/codegraph-php/src/extractor.rs +++ b/crates/codegraph-php/src/extractor.rs @@ -340,15 +340,15 @@ class MyClass { assert!( ir.calls .iter() - .any(|c| c.caller == "process" && c.callee == "validate"), - "Expected process -> validate call" + .any(|c| c.caller == "MyClass::process" && c.callee == "MyClass::validate"), + "Expected MyClass::process -> MyClass::validate call" ); // process -> helper assert!( ir.calls .iter() - .any(|c| c.caller == "process" && c.callee == "helper"), - "Expected process -> helper call" + .any(|c| c.caller == "MyClass::process" && c.callee == "helper"), + "Expected MyClass::process -> helper call" ); } } diff --git a/crates/codegraph-php/src/mapper.rs b/crates/codegraph-php/src/mapper.rs index 4b7f650..0b5bf51 100644 --- a/crates/codegraph-php/src/mapper.rs +++ b/crates/codegraph-php/src/mapper.rs @@ -55,74 +55,6 @@ pub fn ir_to_graph( id }; - // Add functions - for func in &ir.functions { - let mut props = PropertyMap::new() - .with("name", func.name.clone()) - .with("path", file_path.display().to_string()) - .with("signature", func.signature.clone()) - .with("visibility", func.visibility.clone()) - .with("line_start", func.line_start as i64) - .with("line_end", func.line_end as i64) - .with("is_async", func.is_async) - .with("is_static", func.is_static) - .with("is_abstract", func.is_abstract); - - if let Some(ref doc) = func.doc_comment { - props = props.with("doc", doc.clone()); - } - if let Some(ref return_type) = func.return_type { - props = props.with("return_type", return_type.clone()); - } - if let Some(ref parent) = func.parent_class { - props = props.with("parent_class", parent.clone()); - } - if let Some(ref body) = func.body_prefix { - props = props.with("body_prefix", body.clone()); - } - if !func.parameters.is_empty() { - let param_names: Vec = func.parameters.iter().map(|p| p.name.clone()).collect(); - props = props.with("parameters", param_names); - } - if let Some(ref complexity) = func.complexity { - props = props - .with("complexity", complexity.cyclomatic_complexity as i64) - .with("complexity_grade", complexity.grade().to_string()) - .with("complexity_branches", complexity.branches as i64) - .with("complexity_loops", complexity.loops as i64) - .with( - "complexity_logical_ops", - complexity.logical_operators as i64, - ) - .with("complexity_nesting", complexity.max_nesting_depth as i64) - .with( - "complexity_exceptions", - complexity.exception_handlers as i64, - ) - .with("complexity_early_returns", complexity.early_returns as i64); - } - - let func_id = graph - .add_node(NodeType::Function, props) - .map_err(|e| ParserError::GraphError(e.to_string()))?; - - node_map.insert(func.name.clone(), func_id); - function_ids.push(func_id); - - // Link function to file or parent class - if let Some(ref parent_class) = func.parent_class { - if let Some(&class_id) = node_map.get(parent_class) { - graph - .add_edge(class_id, func_id, EdgeType::Contains, PropertyMap::new()) - .map_err(|e| ParserError::GraphError(e.to_string()))?; - } - } else { - graph - .add_edge(file_id, func_id, EdgeType::Contains, PropertyMap::new()) - .map_err(|e| ParserError::GraphError(e.to_string()))?; - } - } - // Add classes for class in &ir.classes { let mut props = PropertyMap::new() @@ -142,6 +74,20 @@ pub fn ir_to_graph( if let Some(ref body) = class.body_prefix { props = props.with("body_prefix", body.clone()); } + // Where an inherited method is looked up, in PHP's order: used traits, + // then the parent class, then interfaces. Lets the cross-file resolver + // follow `$this->inherited()` to the class that declares it. + let traits = ir.implementations.iter().filter(|i| { + i.implementor == class.name && !class.implemented_traits.contains(&i.trait_name) + }); + let inherits: Vec = traits + .map(|i| i.trait_name.clone()) + .chain(class.base_classes.iter().cloned()) + .chain(class.implemented_traits.iter().cloned()) + .collect(); + if !inherits.is_empty() { + props = props.with("inherits", inherits); + } let class_id = graph .add_node(NodeType::Class, props) @@ -177,7 +123,8 @@ pub fn ir_to_graph( // Convention-based HTTP handler detection for Laravel/Symfony: // Public methods in Controller classes are HTTP handlers. - if method.visibility == "public" && is_php_controller_class(&class.name) + if method.visibility == "public" + && is_php_controller_class(&class.name) && !is_php_lifecycle_method(&method.name) { method_props = method_props @@ -234,6 +181,78 @@ pub fn ir_to_graph( .map_err(|e| ParserError::GraphError(e.to_string()))?; } + // Calls made outside any function belong to the file. + node_map.insert(crate::visitor::FILE_SCOPE_CALLER.to_string(), file_id); + + // Add functions and methods. After classes, interfaces and traits, so a + // method can be linked to the type that declares it. + for func in &ir.functions { + // A method is called by `Class::method`; the display name stays bare. + let key = crate::visitor::method_key(func.parent_class.as_deref(), &func.name); + let mut props = PropertyMap::new() + .with("name", func.name.clone()) + .with("qualified_name", key.clone()) + .with("path", file_path.display().to_string()) + .with("signature", func.signature.clone()) + .with("visibility", func.visibility.clone()) + .with("line_start", func.line_start as i64) + .with("line_end", func.line_end as i64) + .with("is_async", func.is_async) + .with("is_static", func.is_static) + .with("is_abstract", func.is_abstract); + + if let Some(ref doc) = func.doc_comment { + props = props.with("doc", doc.clone()); + } + if let Some(ref return_type) = func.return_type { + props = props.with("return_type", return_type.clone()); + } + if let Some(ref parent) = func.parent_class { + props = props.with("parent_class", parent.clone()); + } + if let Some(ref body) = func.body_prefix { + props = props.with("body_prefix", body.clone()); + } + if !func.parameters.is_empty() { + let param_names: Vec = func.parameters.iter().map(|p| p.name.clone()).collect(); + props = props.with("parameters", param_names); + } + if let Some(ref complexity) = func.complexity { + props = props + .with("complexity", complexity.cyclomatic_complexity as i64) + .with("complexity_grade", complexity.grade().to_string()) + .with("complexity_branches", complexity.branches as i64) + .with("complexity_loops", complexity.loops as i64) + .with( + "complexity_logical_ops", + complexity.logical_operators as i64, + ) + .with("complexity_nesting", complexity.max_nesting_depth as i64) + .with( + "complexity_exceptions", + complexity.exception_handlers as i64, + ) + .with("complexity_early_returns", complexity.early_returns as i64); + } + + let func_id = graph + .add_node(NodeType::Function, props) + .map_err(|e| ParserError::GraphError(e.to_string()))?; + + node_map.insert(key, func_id); + function_ids.push(func_id); + + // Link the function to its declaring type, or else to the file + let owner = func + .parent_class + .as_ref() + .and_then(|parent| node_map.get(parent).copied()) + .unwrap_or(file_id); + graph + .add_edge(owner, func_id, EdgeType::Contains, PropertyMap::new()) + .map_err(|e| ParserError::GraphError(e.to_string()))?; + } + // Add import nodes and relationships for import in &ir.imports { let imported_module = &import.imported; diff --git a/crates/codegraph-php/src/visitor.rs b/crates/codegraph-php/src/visitor.rs index 7c853f2..2df6d9c 100644 --- a/crates/codegraph-php/src/visitor.rs +++ b/crates/codegraph-php/src/visitor.rs @@ -4,13 +4,19 @@ //! AST visitor for extracting PHP entities use codegraph_parser_api::{ - CallRelation, ClassEntity, ComplexityBuilder, ComplexityMetrics, FunctionEntity, - ImplementationRelation, ImportRelation, InheritanceRelation, Parameter, TraitEntity, - BODY_PREFIX_MAX_CHARS, - truncate_body_prefix, + truncate_body_prefix, CallRelation, ClassEntity, ComplexityBuilder, ComplexityMetrics, + FunctionEntity, ImplementationRelation, ImportRelation, InheritanceRelation, Parameter, + TraitEntity, }; +use std::collections::HashMap; use tree_sitter::Node; +/// Type names that can never be the receiver class of a method call. +const NON_CLASS_TYPES: &[&str] = &[ + "array", "bool", "callable", "false", "float", "int", "iterable", "mixed", "never", "null", + "object", "string", "true", "void", +]; + pub struct PhpVisitor<'a> { pub source: &'a [u8], pub functions: Vec, @@ -23,6 +29,17 @@ pub struct PhpVisitor<'a> { current_namespace: Option, current_class: Option, current_function: Option, + /// `use A\B\Screen;` maps `Screen` to `A\B\Screen` for the rest of the namespace. + class_aliases: HashMap, + /// `use function A\helper;` maps `helper` to `A\helper`. + function_aliases: HashMap, + /// Fully qualified base class of the class being visited, for `parent::`. + current_parent_class: Option, + /// Declared property types of the class being visited, for `$this->prop->m()`. + property_types: HashMap, + /// Classes of the variables in the function being visited. `None` marks a + /// variable seen with more than one class, which is not a known receiver. + local_types: HashMap>, } impl<'a> PhpVisitor<'a> { @@ -39,6 +56,11 @@ impl<'a> PhpVisitor<'a> { current_namespace: None, current_class: None, current_function: None, + class_aliases: HashMap::new(), + function_aliases: HashMap::new(), + current_parent_class: None, + property_types: HashMap::new(), + local_types: HashMap::new(), } } @@ -95,7 +117,10 @@ impl<'a> PhpVisitor<'a> { false // Skip anonymous functions } // Call expressions - extract call relationships - "function_call_expression" | "member_call_expression" | "scoped_call_expression" => { + "function_call_expression" + | "member_call_expression" + | "nullsafe_member_call_expression" + | "scoped_call_expression" => { self.visit_call_expression(node); true // Recurse to find nested calls } @@ -133,9 +158,7 @@ impl<'a> PhpVisitor<'a> { .child_by_field_name("body") .and_then(|b| b.utf8_text(self.source).ok()) .filter(|t| !t.is_empty()) - .map(|t| { - truncate_body_prefix(t) - }) + .map(truncate_body_prefix) .map(|t| t.to_string()); let func = FunctionEntity { @@ -162,11 +185,13 @@ impl<'a> PhpVisitor<'a> { // Set current function context and visit body to extract calls let previous_function = self.current_function.take(); self.current_function = Some(qualified_name); + let previous_locals = self.enter_function_scope(node); if let Some(body) = node.child_by_field_name("body") { self.visit_function_body(body); } + self.local_types = previous_locals; self.current_function = previous_function; } @@ -190,9 +215,7 @@ impl<'a> PhpVisitor<'a> { .child_by_field_name("body") .and_then(|b| b.utf8_text(self.source).ok()) .filter(|t| !t.is_empty()) - .map(|t| { - truncate_body_prefix(t) - }) + .map(truncate_body_prefix) .map(|t| t.to_string()); let func = FunctionEntity { @@ -216,14 +239,18 @@ impl<'a> PhpVisitor<'a> { self.functions.push(func); - // Set current function context and visit body to extract calls + // Set current function context and visit body to extract calls. + // A method's identity is its class plus its name: two classes' `render` + // are different symbols, and keying calls by the bare name merged them. let previous_function = self.current_function.take(); - self.current_function = Some(name); + self.current_function = Some(method_key(self.current_class.as_deref(), &name)); + let previous_locals = self.enter_function_scope(node); if let Some(body) = node.child_by_field_name("body") { self.visit_function_body(body); } + self.local_types = previous_locals; self.current_function = previous_function; } @@ -248,7 +275,7 @@ impl<'a> PhpVisitor<'a> { let mut bc_cursor = child.walk(); for bc_child in child.named_children(&mut bc_cursor) { if bc_child.kind() == "name" || bc_child.kind() == "qualified_name" { - let base_name = self.node_text(bc_child); + let base_name = self.resolve_class_name(&self.node_text(bc_child)); base_classes.push(base_name.clone()); self.inheritance.push(InheritanceRelation { child: qualified_name.clone(), @@ -271,9 +298,7 @@ impl<'a> PhpVisitor<'a> { .child_by_field_name("body") .and_then(|b| b.utf8_text(self.source).ok()) .filter(|t| !t.is_empty()) - .map(|t| { - truncate_body_prefix(t) - }) + .map(truncate_body_prefix) .map(|t| t.to_string()); let class_entity = ClassEntity { @@ -293,17 +318,23 @@ impl<'a> PhpVisitor<'a> { body_prefix, }; + let parent_class = class_entity.base_classes.first().cloned(); self.classes.push(class_entity); // Set current class context for method extraction let previous_class = self.current_class.take(); self.current_class = Some(qualified_name); + let previous_parent = std::mem::replace(&mut self.current_parent_class, parent_class); + let previous_properties = std::mem::take(&mut self.property_types); // Visit class body to extract methods and trait uses if let Some(body) = node.child_by_field_name("body") { + self.collect_property_types(body); self.visit_class_body(body); } + self.property_types = previous_properties; + self.current_parent_class = previous_parent; self.current_class = previous_class; } @@ -323,7 +354,7 @@ impl<'a> PhpVisitor<'a> { let mut cursor = node.walk(); for child in node.children(&mut cursor) { if child.kind() == "name" || child.kind() == "qualified_name" { - let trait_name = self.node_text(child); + let trait_name = self.resolve_class_name(&self.node_text(child)); self.implementations.push(ImplementationRelation { implementor: class_name.clone(), trait_name, @@ -347,7 +378,7 @@ impl<'a> PhpVisitor<'a> { if let Some(base_clause) = node.child_by_field_name("base_clause") { for child in base_clause.children(&mut base_clause.walk()) { if child.kind() == "name" || child.kind() == "qualified_name" { - parent_traits.push(self.node_text(child)); + parent_traits.push(self.resolve_class_name(&self.node_text(child))); } } } @@ -437,9 +468,7 @@ impl<'a> PhpVisitor<'a> { .child_by_field_name("body") .and_then(|b| b.utf8_text(self.source).ok()) .filter(|t| !t.is_empty()) - .map(|t| { - truncate_body_prefix(t) - }) + .map(truncate_body_prefix) .map(|t| t.to_string()); // PHP 8.1 enums are treated as classes @@ -482,15 +511,40 @@ impl<'a> PhpVisitor<'a> { fn visit_namespace(&mut self, node: Node) { let name = node.child_by_field_name("name").map(|n| self.node_text(n)); + // Imports belong to the namespace that declares them. + self.class_aliases.clear(); + self.function_aliases.clear(); self.current_namespace = name; } fn visit_use(&mut self, node: Node) { - // Extract use statements (imports) + // `use function A\{x, y};` puts the kind on the declaration, + // `use function A\x;` on the clause. + let declared_kind = node + .child_by_field_name("type") + .map(|n| self.node_text(n).to_ascii_lowercase()); let mut cursor = node.walk(); + let mut prefix: Option = None; for child in node.children(&mut cursor) { - if child.kind() == "namespace_use_clause" { - self.extract_use_clause(child); + match child.kind() { + // The shared prefix of a group use: `use A\B\{Foo, Bar};` + "namespace_name" => prefix = Some(self.node_text(child)), + "namespace_use_clause" => { + self.extract_use_clause(child, None, declared_kind.as_deref()) + } + "namespace_use_group" => { + let mut group_cursor = child.walk(); + for clause in child.children(&mut group_cursor) { + if clause.kind() == "namespace_use_clause" { + self.extract_use_clause( + clause, + prefix.as_deref(), + declared_kind.as_deref(), + ); + } + } + } + _ => {} } } } @@ -682,12 +736,26 @@ impl<'a> PhpVisitor<'a> { text.trim_matches(|c| c == '\'' || c == '"').to_string() } - fn extract_use_clause(&mut self, node: Node) { + fn extract_use_clause( + &mut self, + node: Node, + prefix: Option<&str>, + declared_kind: Option<&str>, + ) { let mut cursor = node.walk(); let mut imported = String::new(); let mut alias = None; + let kind = node + .child_by_field_name("type") + .map(|n| self.node_text(n).to_ascii_lowercase()) + .or_else(|| declared_kind.map(str::to_string)); + let alias_node = node.child_by_field_name("alias"); for child in node.children(&mut cursor) { + if alias_node == Some(child) { + alias = Some(self.node_text(child)); + continue; + } match child.kind() { "qualified_name" | "name" => { imported = self.node_text(child); @@ -706,6 +774,23 @@ impl<'a> PhpVisitor<'a> { } if !imported.is_empty() { + let imported = match prefix { + Some(prefix) => format!("{prefix}\\{imported}"), + None => imported, + }; + let imported = imported.trim_start_matches('\\').to_string(); + let local = alias + .clone() + .unwrap_or_else(|| last_segment(&imported).to_string()); + match kind.as_deref() { + Some("function") => { + self.function_aliases.insert(local, imported.clone()); + } + Some("const") => {} + _ => { + self.class_aliases.insert(local, imported.clone()); + } + } let import = ImportRelation { importer: self .current_namespace @@ -722,11 +807,12 @@ impl<'a> PhpVisitor<'a> { /// Visit a call expression and extract the call relationship fn visit_call_expression(&mut self, node: Node) { - // Only record calls if we're inside a function/method - let caller = match &self.current_function { - Some(name) => name.clone(), - None => return, - }; + // A call outside any function runs when the file is executed - the + // usual shape of a template - so the file itself is its caller. + let caller = self + .current_function + .clone() + .unwrap_or_else(|| FILE_SCOPE_CALLER.to_string()); let callee = self.extract_callee_name(node); @@ -756,10 +842,15 @@ impl<'a> PhpVisitor<'a> { "function_call_expression" => { if let Some(function_node) = node.child_by_field_name("function") { match function_node.kind() { - "name" => self.node_text(function_node), + "name" => { + let name = self.node_text(function_node); + // An unqualified call keeps its bare name: PHP falls + // back from the current namespace to the global one + // at run time, so only an import pins it down. + self.function_aliases.get(&name).cloned().unwrap_or(name) + } "qualified_name" => { - // Fully qualified name like \Namespace\func() - self.node_text(function_node) + self.resolve_function_name(&self.node_text(function_node)) } "variable_name" => { // Dynamic call like $callback() @@ -771,12 +862,21 @@ impl<'a> PhpVisitor<'a> { String::new() } } - // Method call: $obj->method(), $this->method() - "member_call_expression" => { - if let Some(name_node) = node.child_by_field_name("name") { - self.node_text(name_node) - } else { - String::new() + // Method call: $obj->method(), $this->method(), $obj?->method() + "member_call_expression" | "nullsafe_member_call_expression" => { + let Some(name_node) = node.child_by_field_name("name") else { + return String::new(); + }; + let method = self.node_text(name_node); + // Qualify the call only when the receiver's class is certain. + // An unknown receiver keeps the bare name rather than being + // pinned to whichever same-named method happens to exist. + match node + .child_by_field_name("object") + .and_then(|object| self.receiver_class(object)) + { + Some(class) => method_key(Some(&class), &method), + None => method, } } // Static method call: Class::method(), self::method() @@ -789,11 +889,15 @@ impl<'a> PhpVisitor<'a> { .unwrap_or_default(); let method = self.node_text(name_node); - // Return as Class::method for static calls - if scope.is_empty() || scope == "self" || scope == "static" { + if scope.is_empty() || scope.starts_with('$') { + return method; + } + let class = self.resolve_class_name(&scope); + // `parent::` with no known base class stays a bare name. + if class.eq_ignore_ascii_case("parent") { method } else { - format!("{}::{}", scope, method) + method_key(Some(&class), &method) } } else { String::new() @@ -810,11 +914,16 @@ impl<'a> PhpVisitor<'a> { match child.kind() { "function_call_expression" | "member_call_expression" + | "nullsafe_member_call_expression" | "scoped_call_expression" => { self.visit_call_expression(child); // Also recurse into arguments for nested calls self.visit_function_body(child); } + "assignment_expression" => { + self.record_assignment(child); + self.visit_function_body(child); + } _ => { self.visit_function_body(child); } @@ -831,7 +940,7 @@ impl<'a> PhpVisitor<'a> { let mut cursor = node.walk(); for child in node.children(&mut cursor) { if child.kind() == "name" || child.kind() == "qualified_name" { - let interface_name = self.node_text(child); + let interface_name = self.resolve_class_name(&self.node_text(child)); implemented_traits.push(interface_name.clone()); self.implementations.push(ImplementationRelation { implementor: class_name.to_string(), @@ -1067,6 +1176,209 @@ impl<'a> PhpVisitor<'a> { } } + /// Fully qualified class for a class name as written at this point in the + /// file, following PHP's rules: a leading `\` is absolute, an imported + /// first segment expands to its import, and anything else is relative to + /// the current namespace. `self`/`static`/`parent` resolve to the class + /// context; `parent` stays as written when the base class is unknown. + fn resolve_class_name(&self, name: &str) -> String { + if let Some(absolute) = name.strip_prefix('\\') { + return absolute.to_string(); + } + match name.to_ascii_lowercase().as_str() { + "self" | "static" => { + return self + .current_class + .clone() + .unwrap_or_else(|| name.to_string()) + } + "parent" => { + return self + .current_parent_class + .clone() + .unwrap_or_else(|| name.to_string()) + } + _ => {} + } + let (first, rest) = match name.split_once('\\') { + Some((first, rest)) => (first, Some(rest)), + None => (name, None), + }; + if let Some(imported) = self.class_aliases.get(first) { + return match rest { + Some(rest) => format!("{imported}\\{rest}"), + None => imported.clone(), + }; + } + self.qualify_name(name) + } + + /// Fully qualified name of a function called by a qualified name. + /// + /// `\foo()` and `\A\foo()` are absolute; `A\foo()` is relative to an + /// imported namespace `A` or else to the current namespace. Function + /// declarations are keyed without a leading `\`, so the call must be too: + /// keeping it was why `\helper()` never matched `helper`. + fn resolve_function_name(&self, name: &str) -> String { + if let Some(absolute) = name.strip_prefix('\\') { + return absolute.to_string(); + } + if let Some((first, rest)) = name.split_once('\\') { + if let Some(imported) = self.class_aliases.get(first) { + return format!("{imported}\\{rest}"); + } + } + self.qualify_name(name) + } + + /// A class named by a type declaration, if it names exactly one class. + fn class_from_type(&self, type_node: Node) -> Option { + let text = self.node_text(type_node); + let text = text.trim().trim_start_matches('?'); + if text.is_empty() || text.contains(['|', '&', '(']) { + return None; + } + if NON_CLASS_TYPES.contains(&text.to_ascii_lowercase().as_str()) { + return None; + } + Some(self.resolve_class_name(text)) + } + + /// The class instantiated by a `new X(...)` expression. + fn created_class(&self, creation: Node) -> Option { + let mut cursor = creation.walk(); + let class = creation + .named_children(&mut cursor) + .find(|c| c.kind() == "name" || c.kind() == "qualified_name")?; + Some(self.resolve_class_name(&self.node_text(class))) + } + + /// The class of a method call's receiver, when it is certain. + fn receiver_class(&self, object: Node) -> Option { + match object.kind() { + "variable_name" => { + let name = self.node_text(object); + if name == "$this" { + self.current_class.clone() + } else { + self.local_types.get(&name).cloned().flatten() + } + } + "parenthesized_expression" => object + .named_child(0) + .and_then(|inner| self.receiver_class(inner)), + "object_creation_expression" => self.created_class(object), + "member_access_expression" | "nullsafe_member_access_expression" => { + let owner = object.child_by_field_name("object")?; + if owner.kind() != "variable_name" || self.node_text(owner) != "$this" { + return None; + } + let property = self.node_text(object.child_by_field_name("name")?); + self.property_types.get(&property).cloned() + } + _ => None, + } + } + + /// Start a function scope whose known variables are its typed parameters. + /// Returns the enclosing scope's variables for the caller to restore. + fn enter_function_scope(&mut self, node: Node) -> HashMap> { + let mut locals = HashMap::new(); + if let Some(params) = node.child_by_field_name("parameters") { + let mut cursor = params.walk(); + for param in params.named_children(&mut cursor) { + let (Some(name), Some(type_node)) = ( + param.child_by_field_name("name"), + param.child_by_field_name("type"), + ) else { + continue; + }; + if let Some(class) = self.class_from_type(type_node) { + locals.insert(self.node_text(name), Some(class)); + } + } + } + std::mem::replace(&mut self.local_types, locals) + } + + /// Learn a variable's class from `$x = new X(...)`. A variable assigned + /// two different classes in one function has no single receiver class. + fn record_assignment(&mut self, node: Node) { + let (Some(left), Some(right)) = ( + node.child_by_field_name("left"), + node.child_by_field_name("right"), + ) else { + return; + }; + if left.kind() != "variable_name" { + return; + } + let variable = self.node_text(left); + let class = if right.kind() == "object_creation_expression" { + self.created_class(right) + } else { + None + }; + let merged = match (self.local_types.get(&variable), class) { + (None, class) => class, + (Some(Some(known)), Some(class)) if *known == class => Some(class), + _ => None, + }; + self.local_types.insert(variable, merged); + } + + /// Declared types of the class's properties, including promoted + /// constructor parameters, so `$this->repo->find()` has a receiver. + fn collect_property_types(&mut self, body: Node) { + let mut cursor = body.walk(); + for member in body.named_children(&mut cursor) { + match member.kind() { + "property_declaration" => { + let Some(class) = member + .child_by_field_name("type") + .and_then(|t| self.class_from_type(t)) + else { + continue; + }; + let mut elements = member.walk(); + for element in member.named_children(&mut elements) { + if element.kind() != "property_element" { + continue; + } + if let Some(var) = element.child_by_field_name("name") { + let name = self.node_text(var); + self.property_types + .insert(name.trim_start_matches('$').to_string(), class.clone()); + } + } + } + "method_declaration" => { + let Some(params) = member.child_by_field_name("parameters") else { + continue; + }; + let mut params_cursor = params.walk(); + for param in params.named_children(&mut params_cursor) { + if param.kind() != "property_promotion_parameter" { + continue; + } + let (Some(var), Some(type_node)) = ( + param.child_by_field_name("name"), + param.child_by_field_name("type"), + ) else { + continue; + }; + if let Some(class) = self.class_from_type(type_node) { + let name = self.node_text(var); + self.property_types + .insert(name.trim_start_matches('$').to_string(), class); + } + } + } + _ => {} + } + } + } + fn qualify_name(&self, name: &str) -> String { if let Some(ref ns) = self.current_namespace { format!("{}\\{}", ns, name) @@ -1076,6 +1388,25 @@ impl<'a> PhpVisitor<'a> { } } +/// Caller key for calls made at file scope; the mapper binds it to the file +/// node. Not a valid PHP identifier, so it cannot collide with a function. +pub(crate) const FILE_SCOPE_CALLER: &str = ""; + +/// The key a method is called and stored by: `Namespace\Class::method`. +/// +/// Shared with the mapper, which must store methods under exactly the name +/// calls to them are recorded with. +pub(crate) fn method_key(class: Option<&str>, method: &str) -> String { + match class { + Some(class) => format!("{class}::{method}"), + None => method.to_string(), + } +} + +fn last_segment(name: &str) -> &str { + name.rsplit('\\').next().unwrap_or(name) +} + #[cfg(test)] mod tests { use super::*; @@ -1286,6 +1617,78 @@ function another_func() {} .any(|c| c.caller == "caller" && c.callee == "another_func")); } + fn callees_of<'v>(visitor: &'v PhpVisitor<'_>, caller: &str) -> Vec<&'v str> { + visitor + .calls + .iter() + .filter(|c| c.caller == caller) + .map(|c| c.callee.as_str()) + .collect() + } + + #[test] + fn calls_are_named_the_way_php_resolves_them() { + let source = br#"save(); + $user?->refresh(); + parent::boot(); + static::make(); + \strlen('x'); + \App\Support\slug('x'); + Util\clean('x'); + format('x'); + trim('x'); + $mixed = new User(); + $mixed = new Article(); + $mixed->save(); + } +} +"#; + let visitor = parse_and_visit(source); + let callees = callees_of(&visitor, "App\\Web\\Page::run"); + for expected in [ + "App\\Model\\Post::save", + "App\\Model\\User::refresh", + "App\\Web\\Base::boot", + "App\\Web\\Page::make", + "strlen", + "App\\Support\\slug", + "App\\Web\\Util\\clean", + "App\\Support\\format", + "trim", + ] { + assert!( + callees.contains(&expected), + "{expected} missing from {callees:?}" + ); + } + // A variable holding two classes is not a known receiver. + assert!(callees.contains(&"save"), "{callees:?}"); + } + + #[test] + fn group_use_imports_keep_their_prefix() { + let visitor = parse_and_visit(b" = visitor + .imports + .iter() + .map(|i| i.imported.as_str()) + .collect(); + assert_eq!(imported, ["App\\Model\\User", "App\\Model\\Post"]); + } + + #[test] + fn file_scope_calls_belong_to_the_file() { + let visitor = parse_and_visit(b" helper, caller -> process + // `$this->` calls are keyed by the declaring class, like the methods. assert!(visitor .calls .iter() - .any(|c| c.caller == "caller" && c.callee == "helper")); + .any(|c| c.caller == "MyClass::caller" && c.callee == "MyClass::helper")); assert!(visitor .calls .iter() - .any(|c| c.caller == "caller" && c.callee == "process")); + .any(|c| c.caller == "MyClass::caller" && c.callee == "MyClass::process")); } #[test] @@ -1332,15 +1735,15 @@ class Calculator { assert_eq!(visitor.calls.len(), 2); - // Check calls: calculate -> helper (self::), calculate -> Helper::format + // `self::` resolves to the enclosing class. assert!(visitor .calls .iter() - .any(|c| c.caller == "calculate" && c.callee == "helper")); + .any(|c| c.caller == "Calculator::calculate" && c.callee == "Calculator::helper")); assert!(visitor .calls .iter() - .any(|c| c.caller == "calculate" && c.callee == "Helper::format")); + .any(|c| c.caller == "Calculator::calculate" && c.callee == "Helper::format")); } #[test] diff --git a/crates/codegraph-server/src/domain/callers.rs b/crates/codegraph-server/src/domain/callers.rs index 4c318f7..cb0be2f 100644 --- a/crates/codegraph-server/src/domain/callers.rs +++ b/crates/codegraph-server/src/domain/callers.rs @@ -190,13 +190,32 @@ pub(crate) async fn get_callees( /// Find other function nodes with the same name but different node ID. /// Used for multi-arch symbol deduplication (e.g. same function in /// backdoorGcc32.c and backdoorGcc64.c). +/// +/// A variant must be the same symbol, not merely share a name: same owning +/// class (or none) and the same qualified name where one is recorded. Methods +/// of two unrelated classes are different symbols, and borrowing one's callers +/// for the other reported calls that never happen. fn find_same_name_variants(graph: &CodeGraph, name: &str, exclude_id: NodeId) -> Vec { + let identity = |node: &codegraph::Node| { + ( + node.properties + .get_string("parent_class") + .map(str::to_owned), + node.properties + .get_string("qualified_name") + .map(str::to_owned), + ) + }; + let Some(target) = graph.get_node(exclude_id).ok().map(identity) else { + return Vec::new(); + }; graph .nodes_iter() .filter_map(|(&nid, node)| { if nid != exclude_id && node.node_type == codegraph::NodeType::Function && node_props::name(node) == name + && identity(node) == target { Some(nid) } else { @@ -224,3 +243,39 @@ fn build_fallback( (None, None) } } + +#[cfg(test)] +mod tests { + use super::*; + use codegraph::{NodeType, PropertyMap}; + + fn add(graph: &mut CodeGraph, name: &str, parent: Option<&str>) -> NodeId { + let mut props = PropertyMap::new().with("name", name); + if let Some(parent) = parent { + props = props + .with("parent_class", parent) + .with("qualified_name", format!("{parent}::{name}")); + } + graph.add_node(NodeType::Function, props).unwrap() + } + + #[test] + fn copies_of_one_free_function_are_variants() { + let mut graph = CodeGraph::in_memory().unwrap(); + let gcc32 = add(&mut graph, "backdoor", None); + let gcc64 = add(&mut graph, "backdoor", None); + assert_eq!( + find_same_name_variants(&graph, "backdoor", gcc32), + vec![gcc64] + ); + } + + #[test] + fn methods_of_different_classes_are_not_variants() { + let mut graph = CodeGraph::in_memory().unwrap(); + let alpha = add(&mut graph, "render", Some("App\\Alpha\\Screen")); + add(&mut graph, "render", Some("App\\Beta\\Screen")); + add(&mut graph, "render", None); + assert!(find_same_name_variants(&graph, "render", alpha).is_empty()); + } +} diff --git a/crates/codegraph-server/src/watcher.rs b/crates/codegraph-server/src/watcher.rs index 02bdbe4..2ae445a 100644 --- a/crates/codegraph-server/src/watcher.rs +++ b/crates/codegraph-server/src/watcher.rs @@ -389,12 +389,35 @@ impl GraphUpdater { // prefer the non-stub version (higher complexity / more lines). let mut symbol_map: std::collections::HashMap = std::collections::HashMap::new(); + // Symbols that say exactly which declaration they are (`qualified_name`, + // e.g. PHP's `App\Screen::render`). A call recorded under such a name + // means that declaration and no other. + let mut qualified_map: std::collections::HashMap = + std::collections::HashMap::new(); + // Bare names shared by several functions, at least one of them a method. + // Methods of different classes are different symbols, so a call by the + // bare name alone cannot say which one it reaches. + let mut name_counts: std::collections::HashMap = + std::collections::HashMap::new(); // Index all functions — prefer non-stub implementations over stubs if let Ok(functions) = graph.query().node_type(NodeType::Function).execute() { for func_id in functions { if let Ok(node) = graph.get_node(func_id) { + if let Some(qualified) = node.properties.get_string("qualified_name") { + let keep = qualified_map.get(qualified).is_none_or(|&existing| { + symbol_weight(graph, func_id) > symbol_weight(graph, existing) + }); + if keep { + qualified_map.insert(qualified.to_string(), func_id); + } + } if let Some(name) = node.properties.get_string("name") { + let is_method = node.properties.get_string("parent_class").is_some() + || node.properties.get_string("is_method") == Some("true"); + let entry = name_counts.entry(name.to_string()).or_default(); + entry.0 += 1; + entry.1 |= is_method; let name = name.to_string(); if let Some(&existing_id) = symbol_map.get(&name) { // Prefer the version with higher complexity (non-stub) @@ -411,12 +434,19 @@ impl GraphUpdater { } } + // Where each type looks up methods it does not declare itself. + let mut inherits: std::collections::HashMap> = + std::collections::HashMap::new(); + // Index all classes if let Ok(classes) = graph.query().node_type(NodeType::Class).execute() { for class_id in classes { if let Ok(node) = graph.get_node(class_id) { if let Some(name) = node.properties.get_string("name") { symbol_map.insert(name.to_string(), class_id); + if let Some(parents) = node.properties.get_string_list_compat("inherits") { + inherits.insert(name.to_string(), parents); + } } } } @@ -433,6 +463,26 @@ impl GraphUpdater { } } + let ambiguous_methods: std::collections::HashSet = name_counts + .into_iter() + .filter(|(_, (count, any_method))| *count > 1 && *any_method) + .map(|(name, _)| name) + .collect(); + let resolve_callee = |callee: &str| -> Option { + if let Some(&id) = qualified_map.get(callee) { + return Some(id); + } + if let Some((class, method)) = callee.rsplit_once("::") { + if let Some(id) = resolve_inherited(&qualified_map, &inherits, class, method) { + return Some(id); + } + } + if ambiguous_methods.contains(callee) { + return None; + } + symbol_map.get(callee).copied() + }; + // Process each file's outgoing import edges let mut edges_to_add: Vec<(codegraph::NodeId, codegraph::NodeId, PropertyMap)> = Vec::new(); @@ -499,35 +549,38 @@ impl GraphUpdater { let mut call_edges_to_add: Vec<(codegraph::NodeId, codegraph::NodeId, PropertyMap)> = Vec::new(); - if let Ok(functions) = graph.query().node_type(NodeType::Function).execute() { - for func_id in functions { - if let Ok(node) = graph.get_node(func_id) { - if let Some(unresolved) = - node.properties.get_string_list_compat("unresolved_calls") - { - for callee_name in &unresolved { - let callee_name = callee_name.as_str(); - if !callee_name.is_empty() { - if let Some(&callee_id) = symbol_map.get(callee_name) { - // Check if we already have a call edge - let already_linked = graph - .get_edges_between(func_id, callee_id) - .map(|edges| { - edges.iter().any(|e| { - graph - .get_edge(*e) - .map(|edge| edge.edge_type == EdgeType::Calls) - .unwrap_or(false) - }) + // Files can call too: PHP records top-level calls (templates) on the + // file node. + let callers: Vec<_> = [NodeType::Function, NodeType::CodeFile] + .into_iter() + .flat_map(|t| graph.query().node_type(t).execute().unwrap_or_default()) + .collect(); + for func_id in callers { + if let Ok(node) = graph.get_node(func_id) { + if let Some(unresolved) = node.properties.get_string_list_compat("unresolved_calls") + { + for callee_name in &unresolved { + let callee_name = callee_name.as_str(); + if !callee_name.is_empty() { + if let Some(callee_id) = resolve_callee(callee_name) { + // Check if we already have a call edge + let already_linked = graph + .get_edges_between(func_id, callee_id) + .map(|edges| { + edges.iter().any(|e| { + graph + .get_edge(*e) + .map(|edge| edge.edge_type == EdgeType::Calls) + .unwrap_or(false) }) - .unwrap_or(false); + }) + .unwrap_or(false); - if !already_linked { - let props = PropertyMap::new() - .with("resolved_by", "cross_file_resolution") - .with("is_direct", "true"); - call_edges_to_add.push((func_id, callee_id, props)); - } + if !already_linked { + let props = PropertyMap::new() + .with("resolved_by", "cross_file_resolution") + .with("is_direct", "true"); + call_edges_to_add.push((func_id, callee_id, props)); } } } @@ -599,6 +652,43 @@ impl GraphUpdater { /// Weight a symbol for deduplication: prefer non-stub implementations. /// Returns a score based on complexity and line count — stubs (empty body, /// single-line return) get low scores, real implementations get high scores. +/// The declaration a `Class::method` call reaches when `Class` does not declare +/// `method` itself: the first ancestor that does, searched breadth-first in +/// each type's `inherits` order. `None` when no indexed ancestor declares it - +/// the method may come from a vendor class outside the workspace, and guessing +/// a same-named method elsewhere is how unrelated classes got linked. +fn resolve_inherited( + qualified_map: &std::collections::HashMap, + inherits: &std::collections::HashMap>, + class: &str, + method: &str, +) -> Option { + const MAX_ANCESTORS: usize = 64; + let mut seen = std::collections::HashSet::from([class.to_string()]); + let mut queue: std::collections::VecDeque<&str> = inherits + .get(class) + .into_iter() + .flatten() + .map(String::as_str) + .collect(); + while let Some(ancestor) = queue.pop_front() { + if !seen.insert(ancestor.to_string()) || seen.len() > MAX_ANCESTORS { + continue; + } + if let Some(&id) = qualified_map.get(&format!("{ancestor}::{method}")) { + return Some(id); + } + queue.extend( + inherits + .get(ancestor) + .into_iter() + .flatten() + .map(String::as_str), + ); + } + None +} + fn symbol_weight(graph: &codegraph::CodeGraph, node_id: codegraph::NodeId) -> u32 { let node = match graph.get_node(node_id) { Ok(n) => n, @@ -1658,4 +1748,155 @@ void helper_func(int x) { .unwrap_or(false) }) } + + /// PHP call resolution across files (#31). Each case parses real source + /// through the registered parser and runs the shared resolver. + mod php_resolution { + use super::*; + + fn resolve(files: &[(&str, &str)]) -> CodeGraph { + let parsers = ParserRegistry::new(); + let mut graph = CodeGraph::in_memory().unwrap(); + for (path, source) in files { + let path = std::path::Path::new(path); + let parser = parsers.parser_for_path(path).expect("PHP parser"); + parser + .parse_source(source, path, &mut graph) + .expect("parse"); + } + GraphUpdater::resolve_cross_file_imports(&mut graph); + graph + } + + fn by_qualified_name(graph: &CodeGraph, qualified: &str) -> codegraph::NodeId { + graph + .query() + .node_type(codegraph::NodeType::Function) + .execute() + .unwrap_or_default() + .into_iter() + .find(|&id| { + graph.get_node(id).ok().and_then(|n| { + n.properties + .get_string("qualified_name") + .map(|q| q == qualified) + }) == Some(true) + }) + .unwrap_or_else(|| panic!("{qualified} not in graph")) + } + + fn file_node(graph: &CodeGraph, path: &str) -> codegraph::NodeId { + graph + .query() + .node_type(codegraph::NodeType::CodeFile) + .property("path", path.to_string()) + .execute() + .unwrap_or_default() + .into_iter() + .next() + .unwrap_or_else(|| panic!("{path} not in graph")) + } + + const SCREENS: [(&str, &str); 2] = [ + ( + "/ws/Alpha.php", + "render(); }\n}\n", + ); + let graph = resolve(&[SCREENS[0], SCREENS[1], caller]); + let run = by_qualified_name(&graph, "App\\Alpha\\Caller::run"); + let alpha = by_qualified_name(&graph, "App\\Alpha\\Screen::render"); + let beta = by_qualified_name(&graph, "App\\Beta\\Screen::render"); + assert!(has_calls_edge(&graph, run, alpha)); + assert!( + !has_calls_edge(&graph, run, beta), + "the heavier same-named method must not win" + ); + } + + #[test] + fn typed_parameters_imports_and_properties_name_the_receiver() { + let caller = ( + "/ws/Uses.php", + "render(); }\n public function viaProperty(): string { return $this->alpha->render(); }\n public function viaLocal(): string { $x = new AlphaScreen(); return $x->render(); }\n}\n", + ); + let graph = resolve(&[SCREENS[0], SCREENS[1], caller]); + let alpha = by_qualified_name(&graph, "App\\Alpha\\Screen::render"); + let beta = by_qualified_name(&graph, "App\\Beta\\Screen::render"); + let page = |m: &str| by_qualified_name(&graph, &format!("App\\Web\\Page::{m}")); + assert!(has_calls_edge(&graph, page("viaParam"), beta)); + assert!(has_calls_edge(&graph, page("viaProperty"), alpha)); + assert!(has_calls_edge(&graph, page("viaLocal"), alpha)); + assert!(!has_calls_edge(&graph, page("viaParam"), alpha)); + } + + #[test] + fn an_unknown_receiver_is_not_guessed() { + let caller = ( + "/ws/Dynamic.php", + "render(); }\n", + ); + let graph = resolve(&[SCREENS[0], SCREENS[1], caller]); + let show = by_qualified_name(&graph, "App\\show"); + assert_eq!(count_calls_edges_from(&graph, show), 0); + } + + #[test] + fn an_inherited_method_resolves_to_the_declaring_class() { + let base = ( + "/ws/Base.php", + "helper() + parent::helper(); }\n}\n", + ); + let graph = resolve(&[base, child]); + let run = by_qualified_name(&graph, "App\\Web\\Child::run"); + let helper = by_qualified_name(&graph, "App\\Core\\Base::helper"); + assert!(has_calls_edge(&graph, run, helper)); + } + + #[test] + fn an_explicit_global_call_resolves() { + let graph = resolve(&[ + ("/ws/functions.php", " Date: Sun, 15 Nov 2026 11:28:21 -0800 Subject: [PATCH 2/2] no-mistakes(review): Set PHP qualified_name only on methods; fix doc placement --- crates/codegraph-php/src/mapper.rs | 5 ++-- crates/codegraph-server/src/watcher.rs | 39 +++++++++++++++++++------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/crates/codegraph-php/src/mapper.rs b/crates/codegraph-php/src/mapper.rs index 0b5bf51..5ea4649 100644 --- a/crates/codegraph-php/src/mapper.rs +++ b/crates/codegraph-php/src/mapper.rs @@ -191,7 +191,6 @@ pub fn ir_to_graph( let key = crate::visitor::method_key(func.parent_class.as_deref(), &func.name); let mut props = PropertyMap::new() .with("name", func.name.clone()) - .with("qualified_name", key.clone()) .with("path", file_path.display().to_string()) .with("signature", func.signature.clone()) .with("visibility", func.visibility.clone()) @@ -208,7 +207,9 @@ pub fn ir_to_graph( props = props.with("return_type", return_type.clone()); } if let Some(ref parent) = func.parent_class { - props = props.with("parent_class", parent.clone()); + props = props + .with("parent_class", parent.clone()) + .with("qualified_name", key.clone()); } if let Some(ref body) = func.body_prefix { props = props.with("body_prefix", body.clone()); diff --git a/crates/codegraph-server/src/watcher.rs b/crates/codegraph-server/src/watcher.rs index 2ae445a..a1faad8 100644 --- a/crates/codegraph-server/src/watcher.rs +++ b/crates/codegraph-server/src/watcher.rs @@ -649,9 +649,6 @@ impl GraphUpdater { } } -/// Weight a symbol for deduplication: prefer non-stub implementations. -/// Returns a score based on complexity and line count — stubs (empty body, -/// single-line return) get low scores, real implementations get high scores. /// The declaration a `Class::method` call reaches when `Class` does not declare /// `method` itself: the first ancestor that does, searched breadth-first in /// each type's `inherits` order. `None` when no indexed ancestor declares it - @@ -689,6 +686,9 @@ fn resolve_inherited( None } +/// Weight a symbol for deduplication: prefer non-stub implementations. +/// Returns a score based on complexity and line count — stubs (empty body, +/// single-line return) get low scores, real implementations get high scores. fn symbol_weight(graph: &codegraph::CodeGraph, node_id: codegraph::NodeId) -> u32 { let node = match graph.get_node(node_id) { Ok(n) => n, @@ -1769,19 +1769,19 @@ void helper_func(int x) { } fn by_qualified_name(graph: &CodeGraph, qualified: &str) -> codegraph::NodeId { + let key = |n: &codegraph::Node| { + n.properties + .get_string("qualified_name") + .or_else(|| n.properties.get_string("name")) + .map(str::to_string) + }; graph .query() .node_type(codegraph::NodeType::Function) .execute() .unwrap_or_default() .into_iter() - .find(|&id| { - graph.get_node(id).ok().and_then(|n| { - n.properties - .get_string("qualified_name") - .map(|q| q == qualified) - }) == Some(true) - }) + .find(|&id| graph.get_node(id).ok().and_then(key).as_deref() == Some(qualified)) .unwrap_or_else(|| panic!("{qualified} not in graph")) } @@ -1852,6 +1852,25 @@ void helper_func(int x) { assert_eq!(count_calls_edges_from(&graph, show), 0); } + #[test] + fn an_unknown_receiver_does_not_bind_a_same_named_global_function() { + let graph = resolve(&[ + ( + "/ws/functions.php", + "render(); }\n", + ), + ]); + let show = by_qualified_name(&graph, "show"); + let global = by_qualified_name(&graph, "render"); + assert!(!has_calls_edge(&graph, show, global)); + assert_eq!(count_calls_edges_from(&graph, show), 0); + } + #[test] fn an_inherited_method_resolves_to_the_declaring_class() { let base = (