Repository navigation
[4.x] Type dto() from the request's createDtoFromResponse() in PHPStan - #565
Open
pindab0ter wants to merge 2 commits into
Open
pindab0ter wants to merge 2 commits into
pindab0ter wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011np691Rnida5v4u3wsaKby
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011np691Rnida5v4u3wsaKby
pindab0ter
marked this pull request as ready for review
October 4, 2026 17:17
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.
PHPStan sees
Response::dto()anddtoOrFail()asmixed, even when the request'screateDtoFromResponse()declares a precise return type. Every call site needs a@varto get the type back:This PR lets PHPStan infer it:
Generics
ResponseandPendingRequestcarry the request that produced them as@template TRequest of Request = Request. The default keeps every existingResponse $responsehint valid without generics.Connector::send()andsendAndRetry()returnResponse<TRequest>for the request passed in;SoloRequest::send()returnsResponse<$this>Response::getRequest()andPendingRequest::getRequest()return the concrete request classResponse::fromPsrResponse()andwithBufferedBody()keep the request typeThe type survives variables and helper methods, since it lives in the type rather than in the call chain:
PHPStan extension
PHPDoc cannot express "the return type of
createDtoFromResponse()onTRequest", so the package ships a small extension, registered the same way as laravel-actions:DtoReturnTypeExtensiontypesdto()anddtoOrFail()as the request'screateDtoFromResponse()return type. A request without its own typed implementation keepsmixedDtoThrowTypeExtensionadds the exceptions declared oncreateDtoFromResponse()todto()anddtoOrFail(), and respectsexceptions.implicitThrowsWith phpstan/extension-installer the extension loads automatically through
extra.phpstan.includes. Without it:Missing
@throwsA separate commit documents exceptions that were thrown but undeclared:
FatalRequestExceptionandRequestExceptiononsend(),sendAndRetry()andSoloRequest::send(),JsonExceptiononjson(),array(),object()andcollect(), andLogicExceptionondtoOrFail().Projects that enable PHPStan's checked exceptions (
exceptions.check.missingCheckedExceptionInThrows) will start getting reports at call sites that don't declare these. That's the intended effect, but it can surface new errors on upgrade, so it may warrant a release note. If you'd rather not ship these in a minor, the commit can be dropped without affecting the rest.Notes
createDtoFromResponse()returnsnull,dto()falls back to the connector's. The response doesn't carry the connector type, so the extension can't account for that fallbackPendingRequestnow prints with its generic馃 Generated with Claude Code
https://claude.ai/code/session_011np691Rnida5v4u3wsaKby