Skip to content

feat(php): capture class constant access as uses_const edges - #231

Open
erhanurgun wants to merge 59 commits into
Graphify-Labs:v4from
OpenLirary:fix/php-class-constant-access
Open

erhanurgun wants to merge 59 commits into
Graphify-Labs:v4from
OpenLirary:fix/php-class-constant-access

Conversation

@erhanurgun

Copy link
Copy Markdown

Fixes #230

What

The PHP AST extractor now recognizes class_constant_access_expression nodes and produces a new uses_const edge from the enclosing function or method to the class that holds the referenced constant or enum case. Previously these references were silently dropped, so projects that use enums or class constants ended up with isolated nodes that looked like dead code.

Why

Current PHP handling only wires up function_call_expression and member_call_expression. Any reference like TimeConstant::HOUR_IN_SECONDS or Status::Active does not become an edge. On real Laravel codebases this loses a large portion of the true coupling.

Full details and reproducer are in issue #230.

How

  • LanguageConfig gains an optional static_const_types frozenset with an empty default, so every other language is untouched.
  • _PHP_CONFIG sets static_const_types=frozenset({"class_constant_access_expression"}).
  • A new branch inside the existing walk_calls dispatcher handles the node. It reads the class reference via the scope field and falls back to the first named child, because tree-sitter-php has exposed the class name under slightly different field layouts across versions.
  • When the class name resolves through label_to_nid, a uses_const edge is emitted. A dedicated seen_static_ref_pairs set prevents double counting while still allowing both a calls edge and a uses_const edge to coexist for the same (caller, target) pair (which is legitimate when a method both calls an instance method and reads a const on the same class).

Tests

  • tests/fixtures/sample_php_static.php is a minimal fixture that holds a TimeConstant class and a CacheService class that reads two of its constants.
  • tests/test_languages.py gains two tests: test_php_finds_static_const_access checks the relation is present, and test_php_static_const_target_is_holding_class verifies the target node is the class that owns the const.
  • Full suite stays green: pytest reports 427 passed.

Backwards compatibility

The change is additive. Other language configs never populate static_const_types, so their behavior is identical to before. Existing PHP tests (test_php_finds_class, test_php_finds_methods, test_php_finds_imports) still pass against the unchanged tests/fixtures/sample.php fixture.

Follow-ups

I have two related patches ready for scoped_call_expression and scoped_property_access_expression, which fix the same class of missing edges for static method calls and static property access. I can open them right after this one lands to keep each review focused.

This PR is marked as draft until you have a chance to weigh in on the approach (in particular, the new relation name uses_const versus reusing calls). I am happy to rename or reshape before you take a proper look.

Minidoracat and others added 30 commits April 8, 2026 19:39
* fix: git hooks fail when graphify is installed via pipx

When installed via pipx, the graphify module is only available in
pipx's isolated venv, not the system python3. The git hooks
(post-commit, post-checkout) hardcoded `python3` which cannot import
graphify in this case.

Detect the correct Python interpreter from the graphify binary's
shebang line, matching the approach already used in skill.md Step 1.
Falls back to python3 for system installs.

* fix: handle env-style shebangs and improve interpreter detection

- Use POSIX `command -v` instead of non-standard `which`
- Parse `#!/usr/bin/env python3` shebangs correctly (previous
  `tr -d ' '` would produce `/usr/bin/envpython3`)
- Add import validation fallback to python3 if resolved interpreter
  cannot import graphify
… buffer

* fix: suppress graspologic ANSI output that breaks PowerShell scrolling

graspologic's leiden() emits ANSI escape sequences (progress bars,
colored warnings) that corrupt PowerShell 5.1's scroll buffer on
Windows, disabling vertical scrolling. Redirect stdout/stderr to
StringIO during leiden() calls to prevent any escape codes from
reaching the terminal.

Add 2 tests verifying cluster() produces no stdout/stderr output.

Fixes Graphify-Labs#19

Co-Authored-By: Claude Opus 4.6 <[email protected]>

* docs: add PowerShell troubleshooting section to Windows skill

Document the PowerShell 5.1 scrolling issue and provide 4
workarounds: upgrade graphify, use Windows Terminal, reset
terminal, or uninstall graspologic to use Louvain fallback.

Fixes Graphify-Labs#19

Co-Authored-By: Claude Opus 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
- Register 'trae' and 'trae-cn' in _PLATFORM_CONFIG (skill-trae.md,
  ~/.trae/skills/ and ~/.trae-cn/skills/, claude_md=False)
- Add CLI subcommands: graphify trae install/uninstall,
  graphify trae-cn install/uninstall (routes to _agents_install/uninstall)
- Update help text with new platform entries
- Create skill-trae.md (Agent-tool based extraction, AGENTS.md integration,
  no PreToolUse hook support per Trae limitations)
- Update README.md and README.zh-CN.md with Trae platform docs

Co-authored-by: lijinshuan <[email protected]>
…y-Labs#109: extension drift, click detection, skill coverage, .graphify_python persistence

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…e relations in innerHTML (#sec)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…y-Labs#127)

Tree-sitter resolves call targets directly from source — marking them
INFERRED was incorrect. Cross-file class-level uses edges remain INFERRED.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
safishamsi and others added 28 commits April 9, 2026 17:46
…he, graphifyignore parent discovery, MCP fixes

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ort.py, bound collision loop

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
 Graphify-Labs#195: skill.md requires general-purpose subagent type for extraction dispatch

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…phify-Labs#222 and bump to 0.4.2

- extract.py: use str(path) for node IDs to prevent same-basename collision (Graphify-Labs#211)
- build.py: normalize from/to edge keys before KeyError (Graphify-Labs#216)
- export.py: guard ZeroDivisionError when graph has no edges (Graphify-Labs#217)
- hooks.py: remove stale CODE_EXTS filter, rebuild on any changed file (Graphify-Labs#222)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…, Graphify-Labs#221 into 0.4.2

- build/validate: accept NetworkX <=3.1 "links" key alongside "edges" (Graphify-Labs#212)
- __main__: skip version check during install/uninstall, deduplicate paths (Graphify-Labs#220)
- all file IO: explicit encoding="utf-8" to prevent crashes on Windows CJK locales (Graphify-Labs#204)
- hooks: add newline="\n" on write to prevent CRLF shebang breakage on Windows (Graphify-Labs#204)
- export: strip trailing .md from safe_name so "CLAUDE.md" doesn't become "CLAUDE.md.md" (Graphify-Labs#221)
- report: add Community Hubs navigation block so Obsidian vault stays connected (Graphify-Labs#221)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
PHP AST extractor already handles function_call_expression and
member_call_expression but skips static const and enum references like
TimeConstant::HOUR_IN_SECONDS or Status::Active. These now produce a
uses_const edge pointing from the calling function to the class that
holds the constant.

Adds a static_const_types field to LanguageConfig so other languages can
opt in. _PHP_CONFIG uses class_constant_access_expression. The walker
resolves the class reference via the scope field with a positional
fallback for tree-sitter-php versions that expose the class name as a
direct name child.

Test: tests/test_languages.py covers sample_php_static.php and asserts
the new relation appears and targets the enclosing class.
@erhanurgun
erhanurgun marked this pull request as ready for review April 12, 2026 02:13

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP extractor misses class_constant_access_expression (enum and constant references)

7 participants