Skip to content
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

[5.5] allows array or multiple params for hasAny helper #22919

Closed
wants to merge 2 commits into from
Closed

[5.5] allows array or multiple params for hasAny helper #22919

wants to merge 2 commits into from

Conversation

bbashy
Copy link
Contributor

@bbashy bbashy commented Jan 25, 2018

Make this the same as has() allowing array or params

Closes #22917

@tillkruss tillkruss changed the title allows array or multiple params for hasAny helper [5.5] allows array or multiple params for hasAny helper Jan 25, 2018
@Dylan-DPC-zz
Copy link

Can you add tests?

@bbashy
Copy link
Contributor Author

bbashy commented Jan 25, 2018

@Dylan-DPC It's an existing function that has tests already. has() and hasAny() are now equal and have the same tests.

@deleugpn
Copy link
Contributor

If you're changing the code, it means the current implementation isn't sufficient for a use-case and would require test for it to avoid regression, so Dylan is right.

@bbashy
Copy link
Contributor Author

bbashy commented Jan 25, 2018

@Dylan-DPC @deleugpn There you go lads.

@sisve
Copy link
Contributor

sisve commented Jan 26, 2018

This is a change to a method signature, thus a breaking change and should not go into the 5.5 release. Perhaps the 5.6 branch?

The problem shows itself when you have classes that derives from Request and overrides the hasAny method.

Warning: Declaration of CustomReques::hasAny(...$keys) should be compatible with Request::hasAny($key)

* @return bool
*/
public function hasAny(...$keys)
public function hasAny($key)
Copy link
Member

@crynobone crynobone Jan 26, 2018

Choose a reason for hiding this comment

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

Could just avoid the breaking change.

public function hasAny(...$keys)
{
    if (isset($keys[0]) && is_array($keys[0])) {
        $keys = $keys[0];
    }

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 that the method signature could be kept and avoid that specific breaking change; but some further digging shows that we already support arrays to Request::hasAny(), so a change like this would introduce other problems.

@sisve
Copy link
Contributor

sisve commented Jan 26, 2018

Only one of the tests actually fails with the current code; $this->assertTrue($request->hasAny(['name', 'email']));. The problem is that it only fails in one place, not another. This is a screaming red flag; 1) we have existing functionality that supports arrays, and 2) the changes to the tests looks organized, but in reality they are (mostly) not verifying any new behavior.

The problem is that Request::hasAny, with arrays as the use-case has them, isn't clearly documented and we're now trying to change it. There's even use-cases like Request::hasAny(['a1', 'a2'], ['b1', 'b2'], ['c1', 'c2']), which complicates things further. This is syntax that already works today. Changing it could break things.

@taylorotwell
Copy link
Member

I agree that it should probably support both but would definitely need to go to 5.6 and appears we need some test improvements?

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.

6 participants