Skip to content

Consitent implementation of union type checking - #193

Merged
dbu merged 2 commits into
php-http:masterfrom
GrahamCampbell:type-errors
Jul 1, 2020
Merged

dbu merged 2 commits into
php-http:masterfrom
GrahamCampbell:type-errors

Conversation

@GrahamCampbell

Copy link
Copy Markdown
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
Comment thread src/PluginClient.php
* @var int $max_restarts
* }
*
* @throws \RuntimeException if client is not an instance of HttpClient or HttpAsyncClient

Copy link
Copy Markdown
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
Copy Markdown
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

@dbu dbu left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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