Commit 056e826
committed
Skip extends-annotation generation when parent class isn't generic
The extends-emission path in ModelAnnotator::addBehaviorExtends()
unconditionally writes a generic extends-annotation pointing at the
parent (with the behavior-array and entity-type templates) for every
table whose parent has a behavior list or entity to project,
regardless of whether the parent class actually declares any template
of its own. When the parent isn't generic — e.g.
Ratings\Model\Table\RatingsTable from dereuromark/cakephp-ratings —
this produces an annotation that PHPStan correctly rejects with the
generics.notGeneric error, breaking the consumer's build until the
line is removed by hand.
Gate the emission on a new parentSupportsGenerics() helper:
- Cake\ORM\Table (long-standing TBehaviors template, plus TEntity
template from 5.3.4) is treated as generic unconditionally.
- Any other parent is reflected and considered generic iff its own
docblock declares a template tag of its own — inheriting from a
generic ancestor without re-declaring the template doesn't make
the subclass generic itself (PHPStan would still report
generics.notGeneric on any consumer's extends annotation pointing
at the subclass).
- A bare extends annotation without generic params is genuinely
redundant with PHP's own extends clause, so non-generic parents
get no extends-annotation line at all rather than a parameter-less
placeholder.
The previous "protected-parent" fixture (AbstractTable — not generic)
loses its extends-annotation line in the test expectation, and the
snapshot annotation count drops accordingly. Two new focused tests
assert the two branches: non-generic custom parent emits nothing, and
Cake\ORM\Table parent still emits the extends-annotation.
Note: orphan extends-annotation lines in already-annotated files are
NOT removed automatically — the orphan-pruning pass only touches tag
types the current run also generates. Consumers need a one-time manual
cleanup, or upstreaming a template tag to their custom base class so
the annotator re-emits and replaces the line.1 parent 98a5b36 commit 056e826
3 files changed
Lines changed: 89 additions & 3 deletions
File tree
- src/Annotator
- tests
- TestCase/Annotator
- test_files/Model/Table
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
593 | 593 | | |
594 | 594 | | |
595 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
596 | 602 | | |
597 | 603 | | |
598 | 604 | | |
599 | 605 | | |
600 | 606 | | |
601 | 607 | | |
602 | 608 | | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
603 | 641 | | |
604 | 642 | | |
605 | 643 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
342 | | - | |
| 342 | + | |
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
| |||
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
497 | 547 | | |
498 | 548 | | |
499 | 549 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
| |||
0 commit comments