validator icon indicating copy to clipboard operation
validator copied to clipboard

Implement `Not` rule

Open vjik opened this issue 2 years ago • 7 comments

new Not(
    new Number(min: 7, max: 12)
)

vjik avatar Dec 27 '22 13:12 vjik

What an expected result for value e.g. not-a-number in that case?

BoShurik avatar Dec 27 '22 13:12 BoShurik

What an expected result for value e.g. not-a-number in that case?

Simple logic: if internal rule is valid, then Not return error, otherwise return success.

vjik avatar Dec 27 '22 13:12 vjik

Looks cool at first, but it's ambiguous. Maybe the provided example is not the best one, but I agree with @BoShurik - can't think where it can be used in practice (not a number). Combining it with Callback is even more confusing (an exception can be thrown, but depending on specific rules is not good).

Also we have $not properties for inverting logic in certain rules, like in Regex. Maybe use interface / trait pair instead like with "skip on empty", "skip on error", "when" only where it's supported / needed?

Also suggest to delay it to after initial release.

arogachev avatar Dec 27 '22 13:12 arogachev

@vjik your example meant to accept numbers not in range 7 and 12 but it also accepts not valid numbers. And it may be not obvious to add additional Number rule

BoShurik avatar Dec 27 '22 14:12 BoShurik

It's synthetic example for show syntax only.

vjik avatar Dec 27 '22 14:12 vjik

It shows that you can't invert all rules. E.g. new Not(new TrueValue()) will accept incorrect input

BoShurik avatar Dec 27 '22 14:12 BoShurik

Let's wait for real use-cases for rule inversion first.

samdark avatar Dec 28 '22 15:12 samdark