-
-
Notifications
You must be signed in to change notification settings - Fork 452
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
Improve client builder and options #728
Conversation
@@ -35,7 +42,7 @@ public static function create(array $options = []); | |||
* | |||
* @return $this | |||
*/ | |||
public function setUriFactory(UriFactory $uriFactory); | |||
public function setUriFactory(UriFactory $uriFactory): self; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I explicitly avoided to use self
in the interfaces because PHP doesn't have covariant returns and this forces anyone implementing this interface to define that the methods returns the interface and not the type of the class itself which can cause issues with fluent interfaces like this one. Please revert everything back
So, for the question related to making the |
Both the first and second point of the list are fine. The last point makes me wonder if we really need it. What's the improvement of having a parameter dedicated to just the DSN instead of passing it directly together with all the other options? |
The only bonus for the third point is that I'm forced to pass it with an array, always, contrary to all other options with have a setter instead. |
This is because you can't change the DSN after creating a client since the transport won't be updated to reflect the new value. The only downside I see in making this change is that you're treating the DSN option differently from the others |
I've reverted the |
The problem with using |
In that regard, The PHPDoc says Yes, we don't have contravariance in PHP so it's not solvable at the language level, but at the IDE level it seems fine to me. |
Yea probably IDEs will be able to work if they give priority to the annotation instead of the typehint, but as you said yourself this problem is in the PHP language itself and we should not try to workaround it using a docblock since it's misleading and doesn't respect the real code |
I've addressed or answered every comment from the review.
I disagree on this. PHPDoc here helps to narrow the type that can be inferred from the code alone, in the same way we document arrays as |
I hope that with this example the reasons why I am against this change are clearer. Let's take as an example the following code: interface HelloWorldInterface
{
/**
* @return $this
*/
public function foo(): self;
}
class HelloWorld implements HelloWorldInterface
{
/**
* {@inheritdoc}
*/
public function foo(): HelloWorldInterface
{
echo 'foo method called' . PHP_EOL;
return $this;
}
public function bar(): self
{
echo 'bar method called' . PHP_EOL;
return $this;
}
}
(new HelloWorld())->foo()->bar()->foo(); This is perfectly fine and runs on PHP, however PHPStan reports an error. Infact the only reason the build is green is because you're ignoring the error in the |
This seems a bug to me: I've moved So I would like to avoid changing the correctness of the code basing our choiches on tools that will be fixed in the future. Unfortunately PSR-5 is still under discussion, so it's not reliable for now. |
This PR addresses a few last things:
ClientBuilder
ctor now acceptsOptions
, not a naked arrayOptions:setDsn
ClientBuilder::__call
that forwarded calls to the optionsClientBuilderInterface
Last thing: should we make
Options
`final?