Prune orphan extends-annotation lines when the extends behavior is on#451
Merged
Merged
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.notGenericon every consumer). It deliberately punted on cleaning up orphan lines already present in consumer files — those stayed in place because the orphan-pruning pass inAbstractAnnotator::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 inAbstractAnnotator:ModelAnnotatoroverrides it to includeExtendsAnnotation::TAGwhenever thetableBehaviorsconfig includesextends. 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-ron 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
tableBehaviorsconfig 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 errorscomposer cs-check— no errorsNew regression test
testAnnotateRemovesOrphanExtendsForNonGenericParentwrites a tmp fixture with an orphan extends line pointing at the non-genericAbstractTable, runs the annotator with the remove flag on, and asserts the line is gone.Downstream verification in
dereuromark/cakephp-sandbox:SandboxRatingsTable.phpbin/cake annotate models -p Sandbox -r -v --filter SandboxRatings-> 1 annotation removed.— orphan line stripped, file now clean