Feature: add support for strict/loose conditions #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While integrating this I came to find that making sure field types are always set is tricky. It especially gets funky when comparing things like integers and floats. After some reflection, I realized that when it comes to fields and basic comparisons, most of the time an equivalent (loose) comparison is more intuitive.
Fact of the matter is, the system as it is isn't even consistent. Our equivalence operators (== and !=) were strict, but ranger operators (>, >=, <, <=) are loose in PHP. So depending on what operator was used it was strict or loose. Hmm.
This PR makes conditions loose by default and adds a
FieldCondition::strict()
method to allow for a "strict mode" to be activated for a given field. It then adds additional checking in strict mode to make all operators type-strict.My only internal debate for this is whether "strict mode" should be a property of the condition or the condition set. It feels like a
$set->passesStrictly()
would be kind of neat. But that would mean its not possible for a set to be mixed, and it feels like the condition itself should determine that (because, well, that is how conditions work).Also, I did think about adding more operators, but I decided that's more confusing as an API, especially when it comes to range operators. I think 95% of the time folks will want loose operators, and this keeps things simple.
Open to suggestions, but I do think adding a strict mode in some regard is valuable, bringing consistency to the framework, and I think it should be loose by default.