Skip to content

fix(lang-php): scope Composer PSR-4 to the importing application - #774

Merged
avidianity merged 9 commits into
mainfrom
fix/issue-762
Dec 2, 2026
Merged

avidianity merged 9 commits into
mainfrom
fix/issue-762

Conversation

@avidianity

@avidianity avidianity commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Resolve PHP PSR-4 imports using the closest Composer manifest and its declared local path dependencies.
Workspace packages can resolve declared dependencies made available by an enclosing workspace.
Shared packages retain every target that their consuming applications resolve.

Closes #762

Tier

Tier 2 from cargo xtask risk-tier --base origin/main, the default for the PHP plugin and CLI test paths.

Task

  • Trace b/main.php to b/src/Service.php.
  • Leave the unrelated a/src/Service.php disconnected.
  • Preserve access to declared local dependencies, including transitive dependencies and enclosing workspace packages.
  • Keep both reachable targets when applications resolve the same shared import differently.

Fail-first test

  • Tests: trace_resolves_php_psr4_in_the_importing_application, trace_resolves_php_psr4_through_declared_path_dependencies, and trace_keeps_php_psr4_targets_from_each_consuming_application.
  • Before the change (2910ef78): 0 passed; 2 failed. The CLI reported b/main.php -> a/src/Service.php and No runtime import path from b/main.php to b/src/Service.php. It also found a path to the undeclared packages/other/src/Extra.php.
  • After the change: 3 passed; 0 failed.
  • Before the consumer graph fix, the updated transitive and shared package cases failed with 1 passed; 2 failed.

Checks

Check Result
PHP CLI trace regressions 3 passed
PHP plugin unit and integration tests 45 existing tests passed
CLI warning for invalid nested Composer path repository 1 passed
PHP workspace cycle integration test 1 passed
Finding ID stability integration test 1 passed
Git hooks Passed
Codeint self-check Passed locally on 52112b28
Independent reviewer PASS on dffe77ad and 52112b28 (3 PHP trace tests rerun independently after the refactor).
Merged-result check Passed locally on 52112b28

Safety proof

  • Safety fact: A PHP import can reach an explicitly declared local package without gaining access to unrelated Composer packages.
  • Proof: The CLI traced the declared library through to its transitive dependency and reached both targets when consuming applications differed. It found no path to the undeclared sibling, the dependency's development namespace, or the same package name in a later path repository.
  • The existing Composer conformance test still resolves the acme/auth class from a sibling workspace package.
  • interrogate: Not run below Tier 3.

Runtime evidence

PASS for the trace feature map at 52112b28.
Run cargo test --locked -p codeint --test integration php_psr4 against the isolated PHP repositories.
The CLI reported b/main.php -> b/src/Service.php and No runtime import path from b/main.php to a/src/Service.php.
The test also checks the graph through the CLI's structured paths and connected output.
Each test removes its temporary repository.

Metric effects on unchanged code

  • Import cycles no longer counts cycles formed by imports into an unrelated application (fixture ratio 0.6667 to 0).
  • Import boundaries no longer reports violations from those false edges (fixture ratio 0.5 to 0).
  • Orphan files identifies the actual classes left unreachable (fixture ratio 0.3333, Finding ID 7f9f19759dc6ca20 to f5128112a45409eb).
  • Unused dependencies credits declared external packages once unrelated local classes stop shadowing them (fixture ratio 1 to 0).
  • Unlisted dependencies reports undeclared external imports that previously resolved into unrelated applications (fixture ratio 0 to 0.3333).
  • Dev dependencies in production reports Production imports of development dependencies previously shadowed by unrelated local classes (fixture ratio 0 to 0.3333).

The combined follow-up for #757 through #763 will increment each affected Metric version once, following ADR 0044.

Gaps

  • Deferred coverage: Full suite runs in CI. Local dependency resolution follows manifest path repositories and package names without running the Composer version solver.
  • Existing skipped-manifest Workspace membership behavior remains outside this change. The nested invalid-glob warning is covered separately.
  • Environmental failures: An initial build lost its shared target directory. Repeated the fail-first and passing runs in the isolated worktree.

Bind PSR-4 rules to the closest Composer manifest and reachable local path dependencies.

Closes #762
@avidianity avidianity closed this Dec 2, 2026
@avidianity avidianity reopened this Dec 2, 2026
@avidianity avidianity closed this Dec 2, 2026
@avidianity avidianity reopened this Dec 2, 2026
@avidianity avidianity closed this Dec 2, 2026
@avidianity avidianity reopened this Dec 2, 2026
@avidianity avidianity closed this Dec 2, 2026
@avidianity avidianity reopened this Dec 2, 2026
@github-actions github-actions Bot added the tier-2 Tier 2 from the tier check label Dec 2, 2026
@avidianity avidianity closed this Dec 2, 2026
@avidianity avidianity reopened this Dec 2, 2026
@avidianity avidianity closed this Dec 2, 2026
@avidianity avidianity reopened this Dec 2, 2026
@avidianity avidianity closed this Dec 2, 2026
@avidianity avidianity reopened this Dec 2, 2026
@avidianity
avidianity merged commit 8f4f32d into main Dec 2, 2026
19 checks passed
@avidianity
avidianity deleted the fix/issue-762 branch December 2, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tier-2 Tier 2 from the tier check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP PSR-4 imports resolve into another application's classes

1 participant