hoaproject/Ruler

"in" operator problem

Closed this issue · 7 comments

Hello,
for a rule like $rule = 'group in ("customer")' an exception is thrown
i don't know if bug or intended.

It appears the "in" doesn't work with a single value only with two or more

Actually, I have assigned @stephpy but he is quite busy right now. I propose myself as the assignee.

Hi,
Can you past the exception please ?

ContextErrorException: Catchable Fatal Error: Argument 2 passed to Hoa\Ruler\Visitor{closure}() must be an array, string given in /mcorp/data/filer_home/cnitu/mcorp/www/api-services/vendor/hoa/ruler/Hoa/Ruler/Visitor/Asserter.php line 112

The easiest fix is to replace

$this->setOperator('in',  function ( $a, Array $b ) { return in_array($a, $b); });

with this

$this->setOperator('in',  function ( $a, $b ) { return in_array($a, is_array($b)?$b:array($b)); });

in Asserter constructor ... or find out where the $b value is set and make the verification there ...

This will be fixed by #12. Since (…) is used for grouping and declaraing arrays, this construction is ambiguous when containing only one element.

Great thanks ...

Are you ok?