Skip to content

Resolve a Client subclass argument only to a client of that subclass - #37

Merged
loevgaard merged 1 commit into
2.xfrom
resolve-client-subclass-arguments
Nov 30, 2026
Merged

loevgaard merged 1 commit into
2.xfrom
resolve-client-subclass-arguments

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Closes #19.

Summary

ClientValueResolver resolves an argument typed with a subclass of Client only 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\Client gets the current client, as before. So does an argument typed with the Client subclass that the application's decorator of ClientContextInterface returns. Before, a subclass-typed argument got a plain Client whenever the current client wasn't that subclass, and calling the controller threw a TypeError.

Evidence

  • Before: the new it_does_not_resolve_arguments_typed_with_a_subclass_the_current_client_is_not_an_instance_of fails: resolve() with an AppClient argument and a plain Client as 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_of fails against a fix that only resolves arguments typed exactly Client.

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 Client subclass are affected. Where they threw a TypeError, they now get a value from another resolver, the argument's default or null, or Symfony's missing-argument error.

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
@loevgaard
loevgaard merged commit e488cb9 into 2.x Nov 30, 2026
19 checks passed
@loevgaard
loevgaard deleted the resolve-client-subclass-arguments branch November 30, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClientValueResolver resolves arguments typed with a subclass of Client, then passes a Client

1 participant