Skip to content

Fix PHP import graph paths and trait use detection - #790

Open
jimmybrancaccio wants to merge 2 commits into
peteromallet:mainfrom
jimmybrancaccio:fix/php-relative-import-graph
Open

jimmybrancaccio wants to merge 2 commits into
peteromallet:mainfrom
jimmybrancaccio:fix/php-relative-import-graph

Conversation

@jimmybrancaccio

@jimmybrancaccio jimmybrancaccio commented Sep 27, 2026 •

Copy link
Copy Markdown

Problem

PHP project discovery can return relative file paths, while the PHP import resolver returns absolute paths. The dependency graph then drops valid imports and reports live classes as orphaned. In MyVideoGameList, the scan reported 66 orphaned files, including Stripe gateways explicitly imported in AppServiceProvider.

The PHP import query also matched class trait use declarations as though they were namespace imports. This produced unused-import findings for required traits such as PasswordValidationRules.

Fix

Match each resolved import against the discovered path style before discarding it. Add a regression test for an absolute PHP import resolved against relative discovery paths.

Restrict the PHP import query to namespace use declarations and add a regression test showing that an unused namespace import is still reported while a trait use is ignored.

Verification

  • Focused import tests: 10 passed.
  • Patched scan of a temporary copy of the affected app code: orphan findings fell to 7.
  • Full suite: 5,652 passed, 153 skipped, 3 existing Bash unused-source tests failed. Those same 3 failures reproduce on an untouched checkout.
  • PHP tree-sitter integration tests after the trait fix: 53 passed.
  • Running the patched unused-import detector across the MyVideoGameList app/ tree returned 0 findings; the previous scan reported 6 trait false positives.

Copilot AI lite review requested due to automatic review settings September 27, 2026 01:41

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Normalize Windows paths and handle cross-drive relpath errors before approval.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Fixes dependency-graph matching when PHP discovery returns relative paths while import resolution returns absolute paths.

Changes:

  • Adds relative-path fallback matching.
  • Adds regression coverage for PHP imports.
File Summary
desloppify/​tests/​lang/​common/​test_treesitter_imports_direct.py Tests absolute-to-relative PHP import matching.
desloppify/​languages/​_framework/​treesitter/​imports/​graph.py Adds relative-path matching logic; portability and cross-drive handling remain unresolved.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +86 to +88
relative = os.path.relpath(resolved, scan_path)
if relative not in file_set:
continue
github-actions Bot added a commit to citizenadam/desloppify that referenced this pull request Sep 27, 2026
@jimmybrancaccio jimmybrancaccio changed the title fix: match relative import graph paths Fix PHP import graph paths and trait use detection Sep 27, 2026
github-actions Bot added a commit to citizenadam/desloppify that referenced this pull request Sep 27, 2026

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.

2 participants