Reduce PHPStan baseline: use class-string instead - #3799
Conversation
There was a problem hiding this comment.
馃煛 Changes recommended
A couple of the new PHPDoc types over-promise (or rely on less-portable syntax) and should be adjusted to keep the type contracts accurate and reliably interpreted by tooling.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR continues the effort to reduce phpstan-baseline.php by addressing underlying type issues, primarily by replacing inline @var casts with more precise class-string<...> typing in field-related code.
Changes:
- Refines field class resolution typing in
FieldRepository::getFieldClassname()so downstream instantiation can be understood by PHPStan. - Improves PHPDoc typing for discriminator-map computation in
FieldDiscriminatorListener, including typed map properties andclass-stringannotations. - Removes PHPStan baseline suppressions that are no longer needed for
FieldDiscriminatorListener.
File summaries
| File | Description |
|---|---|
| src/Repository/FieldRepository.php | Removes an inline cast in the factory path and adds class-string-based typing for field classname discovery. |
| src/Event/Listener/FieldDiscriminatorListener.php | Adds class-string-based typing for discriminator-map computation and removes the inline cast on instantiation. |
| phpstan-baseline.php | Drops ignore entries that should be resolved by the stronger typing changes. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Lite
馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
bobvandevijver
left a comment
There was a problem hiding this comment.
Failing checks seems to be flaky CI, but I do have these two suggestions. Would that make sense?
| } | ||
|
|
||
| /** | ||
| * @return class-string<Field>|null |
There was a problem hiding this comment.
| * @return class-string<Field>|null | |
| * @return class-string<FieldInterface>|null |
Wouldn't that make more sense here?
| ); | ||
|
|
||
| // Classnames of all fields (classes that implement Bolt\Entity\FieldInterface) | ||
| /** @var Collection<int, class-string<Field>> $allFields */ |
There was a problem hiding this comment.
| /** @var Collection<int, class-string<Field>> $allFields */ | |
| /** @var Collection<int, class-string<FieldInterface>> $allFields */ |
Same here?
Follow-up to #3758, continuing the effort to shrink
phpstan-baseline.phpby fixing the underlying type issues instead of suppressing them. (using class-string syntax instead of forcing with@var)