Repository navigation
Type a custom caster's get() by its native return type when it has no docblock - #2294
Merged
Merged
Conversation
Collaborator
Author
|
/psalm-delta |
Contributor
✅ Types: decreased · Performance: unchangedApps: all → 23
How to read this table
✅ m3u-editor: issues +0 −58, 4 changedWall 91.0 → 91.3 s (+0.3 %) · Memory 2 200 → 2 196 MB (−0.2 %) · Coverage 93.37 → 93.39 % Weighted 38 267 → 38 195 (−72, −0.19 %): L1 −45 · L2 −12 · L3 −1
Removed (58)
Changed (4)
✅ agent-fleet: issues +2 −34, 7 changedWall 69.5 → 69.7 s (+0.3 %) · Memory 2 547 → 2 542 MB (−0.2 %) · Coverage 93.82 → 93.84 % Weighted 51 707 → 51 675 (−32, −0.06 %): L1 −31 · L3 −3 · L4 +2
Added (2)
Removed (34)
Changed (7)
head b86db79 · base 647f1c0 (merge-base) · workflow run Informational only — never fails the PR. Pick apps with |
Collaborator
Author
|
/psalm-delta |
Collaborator
Author
|
/psalm-delta |
Contributor
|
| Project | psalm-plugin-laravel |
| Branch | pr-2294 |
| Testbed | intel-v1 |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result seconds (s) (Result Δ%) | Upper Boundary seconds (s) (Limit %) | Peak Memory | Benchmark Result megabytes (MB) x 1e3 (Result Δ%) | Upper Boundary megabytes (MB) x 1e3 (Limit %) |
|---|---|---|---|---|---|---|
| monica | 📈 view plot 🚷 view threshold | 43.05 s(-1.95%)Baseline: 43.91 s | 47.80 s (90.06%) | 📈 view plot 🚷 view threshold | 1.15 MB x 1e3(0.00%)Baseline: 1.15 MB x 1e3 | 1.21 MB x 1e3 (95.24%) |
…ed docblocks Expand the native get() signature in the caster's own context so self, static and parent (including trait methods) name the caster instead of the model, and use it only when the interface's TGet|null is the sole documentation of get().
…d combine Castable casters
…e inherited native get()
Collaborator
Author
|
/psalm-delta all |
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.
A model attribute cast to a custom caster whose
get()has only a native return type (get(...): Money, no@returndocblock) is now typed asMoney, with or without@implements CastsAttributes<Money, Money>.Before
After
Issue to Solve
$castsorcasts()to a custom caster whoseget()declares only a native return type resolved to(TGet:CastsAttributes as mixed)|nullinstead ofMoney.Codebase::getMethodReturnType()for such aget()with the interface's documentingTGet|null.@return Moneydocblock onget()was the only workaround.Related
Fixes #1662
Solution Description
CastResolver::resolveCastsAttributesGet()uses the caster's declared signature return type when the only docblock documentingget()is the interface'sTGet|null.self,staticandparent(including those from a trait) name a caster class, not the model:self/parentbind to the class the method appears in (the one that imported a trait),staticto the configured caster.CastablewhosecastUsing()returns several casters (@return IntCast|StringCast) now reads as the union of what each returns, and is left to Psalm when any member cannot be resolved (it used to take the first resolvable member).CastsAttributesandCastsInboundAttributesreads as the raw column value (Laravel never calls itsget()), directly and through aCastable.CastablewhosecastUsing()cannot be resolved reads asmixed; it no longer falls back to the class's ownget()(Laravel usescastUsing()alone, even for a value object implementing both contracts).castUsing()return that is an intersection (BaseCast&CastsInboundAttributes, also insideclass-string<...>) reads asmixed, since the inbound contract may be one of its parts.4.xfor a documented@return): a non-final caster returned bycastUsing()is trusted as declared, even though a runtime subclass may also implementCastsInboundAttributes.@returndocblock, or one inherited from a base caster (@return Moneyoverget(): object), are unchanged.CasterReturnTypesEmissionTest) asserting that a native-onlyget(): Moneycaster reads asMoney.Checklist
get(): Moneycaster