Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw if a variadic parameter contains unexpected named arguments #11260

Merged
merged 1 commit into from Feb 13, 2024

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Feb 13, 2024

Fixes #11253.

If a method signature has a variadic parameter, you can call that method with any arbitrary named argument that you want. Hooray. However, our codebase rarely expects that and doing so sometimes raises error messages about invalid array access and similar issues.

This practice could also hide typos in named argument calls.

In order to improve the DX on those methods, I'd like to guard the calls to those methods by introducing a trait that validates if a variadic parameter contains any named arguments. If it finds any, an exception is raised that reports those arguments.

I've started with the QueryBuilder class, but I could extend this change to other classes if we agree that this is what we want.

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much fancy syntax… the future is now! 😎

@derrabus derrabus merged commit b6f4220 into doctrine:3.1.x Feb 13, 2024
64 checks passed
@derrabus derrabus deleted the improvement/dx-variadic branch February 13, 2024 17:28
derrabus added a commit to derrabus/orm that referenced this pull request Feb 21, 2024
* 3.1.x:
  Fix Static Analysis folder reference (doctrine#11281)
  Remove broken assertion from DateAddFunction and DateSubFunction (doctrine#11243)
  Account for inversedBy being a non-falsy-string or null
  Improve static analysis on AttachEntityListenersListener
  docs: recommend safer way to disable logging (doctrine#11269)
  Remove unused baseline entries
  Treat '0' as a legitimate trim char
  Add type field mapper documentation to the sidebar
  Mark document as orphan
  Use correction sectionauthor syntax
  Remove unused trait
  [Documentation] Adding link to Postgres upgrade article (doctrine#11257)
  Validate more variadic parameters (doctrine#11261)
  Throw if a variadic parameter contains unexpected named arguments (doctrine#11260)
  Make docs valid according to guides 0.3.3 (doctrine#11252)
  fix: support array-type arg in QB variadic calls (doctrine#11242)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants