Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BrowserKit] Avoid nullable values in some Client's methods #26509

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 1 commit into from
Mar 15, 2018

Conversation

ossinkine
Copy link
Contributor

@ossinkine ossinkine commented Mar 13, 2018

Q A
Branch? master
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
License MIT

I suggest the some methods in Client should not return null for simplify usage.
If you are trying to get response from client when request method was not called, it seems an exception should be throwed.

Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

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

tend to agree 👍 at least for getCrawler() as you should get it from request().

@@ -183,20 +183,28 @@ public function getCookieJar()
/**
* Returns the current Crawler instance.
*
* @return Crawler|null A Crawler instance
Copy link
Contributor

Choose a reason for hiding this comment

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

should be reverted as it's still valid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

null is returned only for BC. There are no cases when null might be returned.

Copy link
Contributor

Choose a reason for hiding this comment

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

fact is it's Crawler|null until 5.0

to me this is different then switching to new API for parameters (@param), we where want users to provide correct input beforehand.

Copy link
Member

Choose a reason for hiding this comment

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

fact is it's Crawler|null until 5.0

we don't document deprecated APIs

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 sounds fair while thinking about it. Deprecation message should tell either way.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

looks legit to me, good if it can help DX
the deprecation messages need some tweaks

*/
public function getCrawler()
{
if (null === $this->crawler) {
@trigger_error(sprintf('The %s() method calling before request() method is deprecated since 4.1 and will throw an exception in 5.0.', __METHOD__), E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

Calling the "%s()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.
(same below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your help, fixed

@nicolas-grekas nicolas-grekas added this to the 4.1 milestone Mar 14, 2018
@nicolas-grekas nicolas-grekas changed the title Avoid nullable values in some Client's methods [BrowserKit] Avoid nullable values in some Client's methods Mar 14, 2018
@Simperfit
Copy link
Contributor

Thanks for contributing to Symfony !

This looks legit to me too.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

(failures unrelated)

*/
public function getCrawler()
{
if (null === $this->crawler) {
@trigger_error(sprintf('Calling the "%s()" method before the "request()" one is deprecated since Symfony 4.1 and will throw an exception in 5.0.', __METHOD__), E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add the exception that would be thrown in 5.0 and comment it? That will help when we remove the deprecation notices. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabpot Please review

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I was not clear enough. We cannot add the @throws annotation yet as that would be wrong, but to ease remving the deprecation notices, you can add a line like this bellow the trigger call:

// throw new BadMethodCallException('...');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@fabpot
Copy link
Member

fabpot commented Mar 15, 2018

Thank you @ossinkine.

@fabpot fabpot merged commit c2c2853 into symfony:master Mar 15, 2018
fabpot added a commit that referenced this pull request Mar 15, 2018
…thods (ossinkine)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[BrowserKit] Avoid nullable values in some Client's methods

| Q             | A
| ------------- | ---
| Branch?       | master | Bug fix?      | yes/no
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | yes <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes <!-- please add some, will be required by reviewers -->
| License | MIT

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->
I suggest the some methods in `Client` should not return `null` for simplify usage.
If you are trying to get response from client when `request` method was not called, it seems an exception should be throwed.

Commits
-------

c2c2853 Avoid nullable values in some Client's methods
@fabpot fabpot mentioned this pull request May 7, 2018
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.

6 participants