Repository navigation
Resolve a Client subclass argument only to a client of that subclass - #37
Merged
Merged
Conversation
ClientValueResolver resolved every argument typed with Client or a subclass of it to the current client, so an argument typed with a subclass got a plain Client and calling the controller threw a TypeError. Since the resolver had returned a value, Symfony didn't ask the other resolvers. The resolver now returns the current client only when it's an instance of the argument's type, and [] otherwise. An argument typed with the Client subclass that the application's decorator of ClientContextInterface returns still gets the current client. Closes #19
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.
Closes #19.
Summary
ClientValueResolverresolves an argument typed with a subclass ofClientonly when the current client is an instance of that subclass.resolve(request, argument) if argument's type isn't Client or a subclass of it return [] # the client context isn't asked - return [current client] + if current client isn't an instance of argument's type + return [] # other resolvers get their turn + return [current client]An argument typed
Setono\Client\Clientgets the current client, as before. So does an argument typed with theClientsubclass that the application's decorator ofClientContextInterfacereturns. Before, a subclass-typed argument got a plainClientwhenever the current client wasn't that subclass, and calling the controller threw aTypeError.Evidence
it_does_not_resolve_arguments_typed_with_a_subclass_the_current_client_is_not_an_instance_offails:resolve()with anAppClientargument and a plainClientas current client returns[Client], not[].After: it passes. So do the full suite (151 tests), PHPStan and ECS. Infection gives 100% MSI and 100% covered MSI.
it_resolves_arguments_typed_with_a_subclass_the_current_client_is_an_instance_offails against a fix that only resolves arguments typed exactlyClient.Merge Danger
Door: two-way
A revert brings back the
TypeError. Nothing is stored or renamed.Blast Radius: controllers
Only controllers with an argument typed with a
Clientsubclass are affected. Where they threw aTypeError, they now get a value from another resolver, the argument's default or null, or Symfony's missing-argument error.