Skip to content

feat(php): type member-call receivers from return types, docblocks, properties and callers - #5697

Open
livingforelvis wants to merge 11 commits into
Graphify-Labs:v8from
livingforelvis:feat/php-receiver-typing
Open

livingforelvis wants to merge 11 commits into
Graphify-Labs:v8from
livingforelvis:feat/php-receiver-typing

Conversation

@livingforelvis

@livingforelvis livingforelvis commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change

  • New feature

Verification & Invariants

  • Invariant: a receiver binds only when its type evidence names one class, or related classes the code shows (if arms, callers); anything else binds nothing

  • Invariant: no calls edge on v8 is dropped; an unknown chain step falls back to the file table

  • Invariant: unrelated classes that share a method name are never reached (each new test file has same-named decoy classes in other files)

  • Limitation: interfaces are not in the class lineage, so callers passing an interface and a class that implements it meet at no common base, and that parameter stays untyped

  • Limitation: override fan-out is bounded by "some non-test function returns the class", not by data flow, so it can list overrides that never run from a given call site

  • Limitation: insteadof/as trait rules, __call, and variable method names stay unresolved, as before

  • Read the CONTRIBUTING.md guide.

  • Reproduced the issue and identified the invariant.

  • Made the smallest fix necessary.

  • Added a regression test.

  • Kept the PR description synchronized with the final implementation.

  • Documented any limitations / unsupported cases explicitly.

How was this tested?

  • Review fixes (3bc7ea8): test_a_test_caller_types_no_parameter, test_a_test_caller_does_not_widen_what_production_passes, test_a_private_base_method_reaches_no_override
  • New tests: test_php_return_type_receivers.py, test_php_property_types.py, test_php_override_dispatch.py, test_php_parameter_types.py, test_php_branch_alternatives.py
code under test pytest on the 5 new files
origin/v8 (d249de3) 32 failed, 17 passed
this branch 49 passed

Repro from the issue (4 files), calls edges from Validator::check():

v8 this branch
.get_actions_instance() -> Factory.php missing INFERRED
.is_game_over() -> Actions.php missing INFERRED
.is_game_over() -> OtherActions.php (decoy) missing missing

Large legacy PHP codebase (.inc as PHP), whole-graph calls edges from PHP callers:

EXTRACTED INFERRED DERIVED total
v8 d249de3 49,360 16,487 38,176 104,023
this branch 49,360 58,816 30,961 139,137
  • Same codebase, 14 entry flows traced 5 calls deep over the graph: unresolved call sites 11,635 -> 6,307; functions reached 13,725 -> 19,954
  • 15 random new INFERRED edges, read against the source: each lands on the receiver's own class or an override in a subclass a factory returns; 0 on an unrelated class
  • if/else rule alone, edges vs the previous commit: 41 added, 182 removed; the removed are base-class fan-outs replaced by the classes the callers actually pass (one call site: 66 targets -> 6, the six factories that call it)
  • Full suite run the way ci.yml runs it (-n auto -m "not serial", then -m serial) on Python 3.11 and 3.13: 1 and 2 failures, all in test_the_pool_hands_its_workers_the_overrides / test_extract_honours_max_workers_argument; both pass when run alone on each version

Graphify-specific checklist

  • No skill artifact sources changed
  • AST/structural extraction stays deterministic
  • No unsafe interpolation into shell/Python
  • No API keys or local-only graph data included

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Thanks for the pull request, @livingforelvis. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Dec 1, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Review before merging · Merge confidence 3/5

2 bugs · High impact

The PHP extractor now tracks receiver types through returns, locals, properties, and parameters.

P2  Same-line PHP methods reuse the first method’s receiver data · engine.py:1414

Bug  Qualified PHP docblock types can bind to the wrong class · engine.py:1192

What this review covered
  • One review pass used all of its turns for reading code, so it reported from what it had already read.
  • A changed file's diff was too long to show in full, so the review may not have seen every changed line in it; the in-depth pass still reviewed every changed file.
  • 8 of 8 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 6634 functions depend on this change
  • 7 functions became more coupled. Largest: _extract_generic() (23 callers), origin_type() (3 callers), _resolve_php_member_calls() (2 callers).
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed 3bc7ea8 · 2 earlier findings not re-checked

Comment thread graphify/extract.py Resolved
Comment thread graphify/extract.py Resolved
Comment on lines +1411 to +1414
for entries in binds.values():
entries.sort(key=lambda b: (b[0], b[1]))
if params or binds or props or returns or news or calls or any(order):
scopes.setdefault(str(n.start_point[0] + 1), {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2  Same-line PHP methods reuse the first method’s receiver data

When multiple methods begin on the same line, later methods can be resolved using the first method’s parameters and assignments, producing incorrect or missing call edges.

Key PHP scopes by function rather than starting line in _php_function_scopes.

Evidence · checked against the code

Expected: The later method’s receiver type is inferred from that method’s scope.
Actually: The line-keyed scope map retains the first populated scope, which the resolver then uses for the later method’s receiver inference.

  • Independent source review: Checked the PHP member-call tests: they cover receiver resolution and method calls, but their methods are on separate lines and they do not exercise same-line scope collisions. The resolver’s scope lookup is keyed by the caller’s line; no per-method key or other same-line disambiguation was found in the inspected path.
  • This affects methods whose recorded starting lines are identical; the added tests use methods on separate lines.
Prompt to fix with AI
In graphify/extractors/engine.py, _php_function_scopes (lines 1411-1414):
Problem: Same-line PHP methods reuse the first method’s receiver data
Expected: The later method’s receiver type is inferred from that method’s scope.
Actually: The line-keyed scope map retains the first populated scope, which the resolver then uses for the later method’s receiver inference.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

Comment on lines +1190 to +1192
if not re.fullmatch(r"\\?[A-Za-z_]\w*(?:\\[A-Za-z_]\w*)*", arm) or arm.lower() in _PHP_DOC_SCALARS:
return None
return arm.rsplit("\\", 1)[-1]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug  Qualified PHP docblock types can bind to the wrong class

A receiver documented as \Vendor\Actions can be resolved to an unrelated Actions class in the scanned project.

Preserve qualified names from _php_doc_type during class resolution.

Evidence · checked against the code
  • Independent source review: Checked the unique-match resolver and the receiver inference path. Both names are reduced to their final component, and a sole matching project class is accepted. The inspected tests cover unqualified docblock types but do not demonstrate a guard for a qualified type colliding with an unrelated class.
  • The report concerns docblock types; namespace resolution for other PHP type sources may have separate existing behavior.
Prompt to fix with AI
In graphify/extractors/engine.py, _php_doc_type (lines 1190-1192):
Problem: Qualified PHP docblock types can bind to the wrong class
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: type PHP member-call receivers from return types, docblocks, properties and callers

1 participant