Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Support traversables inside in operator #113

Closed
wants to merge 2 commits into from
Closed

Support traversables inside in operator #113

wants to merge 2 commits into from

Conversation

ostrolucky
Copy link

No description provided.

@coveralls
Copy link

coveralls commented Jan 2, 2018

Coverage Status

Coverage increased (+0.02%) to 97.407% when pulling 3e60a63 on ostrolucky:in-traversable into 28174ca on hoaproject:master.

@Pierozi Pierozi self-requested a review January 2, 2018 14:54
Pierozi
Pierozi previously requested changes Jan 2, 2018
Copy link
Member

@Pierozi Pierozi left a comment

Choose a reason for hiding this comment

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

Using foreach looks fine to me, in this case the performance should be similar.

Visitor/Asserter.php Outdated Show resolved Hide resolved
@@ -89,7 +89,15 @@ public function __construct(Ruler\Context $context = null)
$this->setOperator('>=', function ($a, $b) { return $a >= $b; });
$this->setOperator('<', function ($a, $b) { return $a < $b; });
$this->setOperator('<=', function ($a, $b) { return $a <= $b; });
$this->setOperator('in', function ($a, array $b) { return in_array($a, $b); });
$this->setOperator('in', function ($a, $b) {
Copy link
Member

@stephpy stephpy Jan 4, 2018

Choose a reason for hiding this comment

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

IMHO we still have to make a check:

if (false === is_array($b) && !$b instanceof \Traversable ) {
  throw new \InvalidArgumentException(....
}

Copy link
Author

Choose a reason for hiding this comment

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

Well similar error would be produced by PHP automatically during foreach call, no need to do it ourselves. But will do anyway.

@Pierozi Pierozi dismissed their stale review January 4, 2018 10:28

Replaced by @stephpy request

@coveralls
Copy link

coveralls commented Jan 5, 2018

Coverage Status

Coverage decreased (-0.2%) to 97.232% when pulling 53a2842 on ostrolucky:in-traversable into 28174ca on hoaproject:master.

@@ -308,12 +308,18 @@ public function case_operator_in_empty_array()

public function case_operator_in()
{
return $this->_case_boolean_operator('in', [7, [1, 3, 5, 7, 9]], true);
$this->_case_boolean_operator('in', [7, [1, 3, 5, 7, 9]], true);
Copy link
Member

Choose a reason for hiding this comment

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

This test case now contains 2 test cases. Please, split it :-).

Copy link
Author

Choose a reason for hiding this comment

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

It's ok if test case contains multiple asserts. But ok will split.

}

public function case_operator_in_falsy()
{
return $this->_case_boolean_operator('in', [42, [1, 3, 5, 7, 9]], false);
$this->_case_boolean_operator('in', [42, [1, 3, 5, 7, 9]], false);
Copy link
Member

Choose a reason for hiding this comment

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

Same, please split the test case.

$this->setOperator('in', function ($a, array $b) { return in_array($a, $b); });
$this->setOperator('in', function ($a, $b) {
if (false === is_array($b) && !$b instanceof \Traversable) {
throw new \InvalidArgumentException(sprintf('Expect iterable, got %s', get_class($b)));
Copy link
Member

Choose a reason for hiding this comment

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

Please throw a Hoa\Ruler\Exception\Asserter instance.

@@ -89,7 +89,19 @@ public function __construct(Ruler\Context $context = null)
$this->setOperator('>=', function ($a, $b) { return $a >= $b; });
$this->setOperator('<', function ($a, $b) { return $a < $b; });
$this->setOperator('<=', function ($a, $b) { return $a <= $b; });
$this->setOperator('in', function ($a, array $b) { return in_array($a, $b); });
$this->setOperator('in', function ($a, $b) {
Copy link
Member

Choose a reason for hiding this comment

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

Why not using the iterable type hint?

Copy link
Author

Choose a reason for hiding this comment

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

you support PHP 5.6

Copy link
Member

Choose a reason for hiding this comment

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

We are dropping PHP 5.x support. So go on :-).

Copy link
Author

Choose a reason for hiding this comment

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

Ok but iterable typehint is available since PHP 7.1 only. So can I drop all other versions from travis matrix?

@Hywan
Copy link
Member

Hywan commented Jan 8, 2018

Thanks for the PR!

@ostrolucky
Copy link
Author

@Hywan No problem! So, how should we go forward with this? Do you want me to typehint to iterable and drop support for PHP < 7.1, or just change the type of exception thrown?

@Hywan
Copy link
Member

Hywan commented Jan 22, 2018

@ostrolucky We are discussing about merging the php7 branch into master, so that's it's going to be much easier for you. Sorry for the late reply, I'm back from my paternity leave :-).

@ostrolucky
Copy link
Author

All I see on gh is master branch, no php7?

@Hywan
Copy link
Member

Hywan commented Feb 5, 2018

php7 has been merged inside master.

@Hywan
Copy link
Member

Hywan commented Feb 5, 2018

Or it's about to be :-p.

@ostrolucky
Copy link
Author

Still no php7. Let's merge it as it is

This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

None yet

6 participants