Skip to content

Consitent implementation of union type checking #193

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

Merged
merged 2 commits into from
Jul 1, 2020
Merged

Consitent implementation of union type checking #193

merged 2 commits into from
Jul 1, 2020

Conversation

GrahamCampbell
Copy link
Contributor

Q A
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
License MIT

This PR consistently implements union type checking. Note that in the cases where there wasn't already a type check in place, the code would have still crashed later, but it is much harder for a programmer to know what went wrong, because it wasn't thrown early enough, where they actually made the made method called, and instead was thrown from deeper in the internals.

@GrahamCampbell GrahamCampbell marked this pull request as draft July 1, 2020 13:42
@@ -50,8 +50,6 @@ final class PluginClient implements HttpClient, HttpAsyncClient
*
* @var int $max_restarts
* }
*
* @throws \RuntimeException if client is not an instance of HttpClient or HttpAsyncClient
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doc was incorrect anyway, so I think my change is fine, and can be regarded as a bug fix.

NB In general, I don't think we ever need throws docs for "Errors", only "Exceptions", so this is why I've not added any. One can think of Errors in PHP just like how Java's type system treats RuntimeExceptions.

Copy link
Contributor

Choose a reason for hiding this comment

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

i agree 👍

@GrahamCampbell GrahamCampbell marked this pull request as ready for review July 1, 2020 13:52
Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

great! yep, i agree and really hope people don't pass the wrong type of argument and then catch the LogicException...

@dbu dbu merged commit 38b66ea into php-http:master Jul 1, 2020
@GrahamCampbell GrahamCampbell deleted the type-errors branch July 1, 2020 13:57
@GrahamCampbell
Copy link
Contributor Author

🚀

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.

2 participants