Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions libs/openant-core/parsers/php/call_graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,6 @@ def _resolve_member_call(self, node, source: bytes, caller_file: str,
if not method_name:
return None

if self._is_builtin(method_name):
return None

# $this->method() - same class
if receiver == '$this' and caller_class:
return self._resolve_self_call(method_name, caller_file, caller_class)
Expand Down Expand Up @@ -486,9 +483,6 @@ def _resolve_scoped_call(self, node, source: bytes, caller_file: str,
if scope == 'Closure' and method_name == 'fromCallable':
return self._resolve_callback_arg(node, source, caller_file, caller_class, 0)

if self._is_builtin(method_name):
return None

# self::method() or static::method() - same class
if scope in ('self', 'static') and caller_class:
return self._resolve_self_call(method_name, caller_file, caller_class)
Expand Down
49 changes: 49 additions & 0 deletions libs/openant-core/tests/parsers/php/test_call_graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,55 @@ def test_bare_call_resolves_within_same_namespace():
)


def test_this_call_to_builtin_named_same_class_method_resolves():
"""$this->count() must edge to the same-class count() method (B2).

A same-class method named like a PHP builtin (count/next/key) was dropped by a
premature _is_builtin() short-circuit in _resolve_member_call before it could
route to _resolve_self_call. Driven through the real builder on real PHP source.
"""
funcs = {
"bag.php:Bag::count": {
"name": "count", "file_path": "bag.php", "class_name": "Bag",
"namespace_name": None,
"code": "function count() { return 1; }",
},
"bag.php:Bag::total": {
"name": "total", "file_path": "bag.php", "class_name": "Bag",
"namespace_name": None,
"code": "function total() { return $this->count() * 2; }",
},
}
b = _build(funcs)
assert b.call_graph.get("bag.php:Bag::total") == ["bag.php:Bag::count"], (
f"$this->count() must resolve to same-class count(): {b.call_graph}"
)


def test_scoped_call_to_builtin_named_same_class_method_resolves():
"""self::count() must edge to the same-class count() method (B2).

Same bug in _resolve_scoped_call: the premature _is_builtin() short-circuit
dropped self::/static::/Class:: calls to a builtin-named own method.
"""
funcs = {
"bag.php:Bag::count": {
"name": "count", "file_path": "bag.php", "class_name": "Bag",
"namespace_name": None,
"code": "function count() { return 1; }",
},
"bag.php:Bag::total": {
"name": "total", "file_path": "bag.php", "class_name": "Bag",
"namespace_name": None,
"code": "function total() { return self::count() * 2; }",
},
}
b = _build(funcs)
assert b.call_graph.get("bag.php:Bag::total") == ["bag.php:Bag::count"], (
f"self::count() must resolve to same-class count(): {b.call_graph}"
)


def test_same_file_name_colliding_globals_all_resolved():
"""Two method-nested `function g(){}` in one file (re-keyed to file-scope
globals with de-collided ids `app.php:g` / `app.php:g#L9`) must BOTH receive an
Expand Down
Loading