-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat: typesafety for client options (new surface only) #450
Merged
Conversation
This file contains 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
…nto add-options-classes
bshaffer
commented
Mar 31, 2023
bshaffer
commented
Mar 31, 2023
noahdietz
reviewed
Jul 6, 2023
Co-authored-by: Noah Dietz <[email protected]>
noahdietz
approved these changes
Jul 6, 2023
Added |
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.
Add classes to wrap our current typeless array for Client Options. There is a different "Options" class for each "layer" of options (e.g. nested array), so that we have typehinted classes with corresponding docs instead of untyped associative arrays. This will allow us to have consistent options across our various classes, including handwritten clients.
An overview of the design decisions
ArrayAccess
inOptionsTrait
so that the getters do not show up in the docs or IDEs. This is just a nice convenience factor, since the getters shouldn't be used or be considered very important. It also causes less churn for our internal code, since we were previously using array access.toArray()
before passing them anywhere). This is because I didn't want to widen (e.g. remove) thearray
typehints (as union types aren't available until PHP 8.0! 😡). If we decide to do it this way (we can always widen later), we should at least add a reference (e.g.@see ClientOptions
), etc, to everywhere it's applicable, so users can find the docs.null
says something different. I did not allow arrays/booleans to be nullable, because I don't think that distinction means anything (and it just makes the code look sloppier).cc @saranshdhingra and @noahdietz - This is a draft! I am not hard-set on any of these design decisions! I would still love your feedback!
CallOptions