Skip to content

Prune orphan extends-annotation lines when the extends behavior is on#451

Merged
dereuromark merged 1 commit into
masterfrom
fix/prune-orphan-extends-when-behavior-on
May 20, 2026
Merged

Prune orphan extends-annotation lines when the extends behavior is on#451
dereuromark merged 1 commit into
masterfrom
fix/prune-orphan-extends-when-behavior-on

Conversation

@dereuromark
Copy link
Copy Markdown
Owner

Follow-up to #450.

Summary

#450 stopped the annotator from emitting a parameterized extends-annotation for non-generic parents (which would otherwise trigger PHPStan's generics.notGeneric on every consumer). It deliberately punted on cleaning up orphan lines already present in consumer files — those stayed in place because the orphan-pruning pass in AbstractAnnotator::appendToExistingDocBlock() only deletes tags whose type matches a tag the current run actually generated. When the annotator now emits zero extends-annotation lines, the existing one isn't in the generated-tag set and gets unset from the removal queue.

Approach

Add a managedTags() hook in AbstractAnnotator:

  • Default behavior unchanged — returns the set of tags actually generated this pass.
  • Subclasses can widen it with tag types they own regardless of whether the current pass produced one.

ModelAnnotator overrides it to include ExtendsAnnotation::TAG whenever the tableBehaviors config includes extends. So in any project that has the extends behavior on, an orphan extends-annotation line — whether left over from a previous run, an old config, or copy-pasted by hand — is now reported as outdated on a plain run and pruned by -r on the next run.

Projects that explicitly hand-wrote an extends-annotation against a non-Cake parent are unaffected if they've disabled the extends behavior (the tableBehaviors config check gates the widening).

Verification

Plugin-level:

  • vendor/bin/phpunit — 301 tests, 944 assertions, all green (+1 new regression test over master)
  • composer stan — no errors
  • composer cs-check — no errors

New regression test testAnnotateRemovesOrphanExtendsForNonGenericParent writes a tmp fixture with an orphan extends line pointing at the non-generic AbstractTable, runs the annotator with the remove flag on, and asserts the line is gone.

Downstream verification in dereuromark/cakephp-sandbox:

  • Restored the orphan extends-annotation in SandboxRatingsTable.php
  • Dropped the patched annotator into vendor, re-ran bin/cake annotate models -p Sandbox -r -v --filter SandboxRatings
  • Output: -> 1 annotation removed. — orphan line stripped, file now clean

…nfigured

Background: PR #450 stopped emitting an extends-annotation for non-generic
parents (where it would otherwise trigger generics.notGeneric on every
consumer), but already-annotated consumer files kept their orphan lines.
The orphan-pruning pass in AbstractAnnotator::appendToExistingDocBlock()
only deletes existing tags whose type matches a tag the current run
generated — when we now emit no extends-annotation, the existing
ExtendsAnnotation::TAG isn't in the generated-tag set and the line gets
unset from the removal queue.

Add a managedTags() hook that subclasses can widen with tag types they
own regardless of whether the current pass produced one. ModelAnnotator
overrides it to include the extends tag type whenever the table behaviors
configuration includes "extends" — so an orphan line left over from a
previous run (or from upgrading past the parent-genericness gate) gets
flagged as removable on a plain run and pruned by -r on the next run.

A regression test writes a tmp fixture with an orphan extends line,
runs the annotator with the remove flag on, and asserts the line is gone.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 20, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.60%. Comparing base (ed9e9a5) to head (45634dd).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #451      +/-   ##
============================================
+ Coverage     84.57%   84.60%   +0.03%     
- Complexity     2229     2233       +4     
============================================
  Files           122      122              
  Lines          5918     5925       +7     
============================================
+ Hits           5005     5013       +8     
+ Misses          913      912       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dereuromark dereuromark merged commit 71bd8b2 into master May 20, 2026
16 checks passed
@dereuromark dereuromark deleted the fix/prune-orphan-extends-when-behavior-on branch May 20, 2026 23:55
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