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

Incompatibilities between 0.2.0 and 03.0 #48

Open
robap opened this issue Dec 3, 2016 · 0 comments
Open

Incompatibilities between 0.2.0 and 03.0 #48

robap opened this issue Dec 3, 2016 · 0 comments

Comments

@robap
Copy link

robap commented Dec 3, 2016

I recently attempted to upgrade from 0.2.0 to 0.3.0 and found that the contains operators are incompatible because the argument orders are reversed.

This code dumps "true" for version 0.2.0 and "false" for version 0.3.0:

$haystack = new \Ruler\Variable('haystack');
$needle = new \Ruler\Variable('needle');

$rule = new Ruler\Rule(new Ruler\Operator\LogicalAnd([
        new Ruler\Operator\Contains($needle, $haystack)
    ])
);

$context = new \Ruler\Context([
    'haystack' => 'The quick brown fox',
    'needle' => 'quick',
]);
var_dump($rule->evaluate($context));

I realize that in 0.3.0 the contains operator is deprecated. If I replace the contains operator usage above with StringContains, false instead of true is dumped out.
The difference appears to be in the class Value and how strpos is called:
https://github.com/bobthecow/Ruler/blob/v0.2.0/src/Ruler/Value.php#L73
https://github.com/bobthecow/Ruler/blob/v0.3.0/src/Ruler/Value.php#L92

I suspect part of the issue is the ambiguity of left/right - clearly the author in 0.2.0 had one idea and the author of 0.3.0 had a different idea about what left/right meant. It would be helpful to clarify this in the documentation and to note the incompatibility so that would be upgraders won't be in for an unpleasant surprise.

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

No branches or pull requests

1 participant