Fixed MultiConstraint with MatchAllConstraint#129
Conversation
|
Don't understand phpstan, none of the methods in this test have any return type. |
|
I kinda wonder if this is worth fixing from a performance standpoint, it adds a loop on every multi constraint for a case which will most likely almost never happen as it's really nonsense constraints.. And it's not like it was broken before, it just returns a slightly optimized version now. |
|
I just noticed because I did |
|
This change is causing a Must provide at least two constraints for a MultiConstraint error, because now that there is an if (0 === \count($constraints)) {
return new MatchAllConstraint();
}
if (1 === \count($constraints)) {
return $constraints[0];
}
foreach ($constraints as $k => $constraint) {
if ($constraint instanceof MatchAllConstraint) {
if (!$conjunctive) {
return new MatchAllConstraint();
}
unset($constraints[$k]);
}
}
// Due to the new unset() above, $constraints can have 0 or 1 member(s) here again,
// so the checks from above might have to be moved here or copied here.
$optimized = self::optimizeConstraints($constraints, $conjunctive); |
|
Ah yes.. 84ce71b should fix this I believe |
|
Unfortunately, it does not:
|
|
Yeah reset works, but unfortunately in more complex cases this will still blow up in optimizeConstraint, we'd have to call array_values always there to make sure we have a packed array without gaps for the I think I will just revert this and done. It was already not really worth it to begin with, but it's only getting worse. |
|
Thank you. 👍 |
I'm not sure if this is correct but I'm fairly sure the current behaviour is incorrect :D
If I create a
MultiConstraintwith any instance ofMatchAllConstraint, I currently get aMultiConstraintback which seems strange.>= 2.5.0 AND *should return either aMatchAllConstraintor aMatchNonConstraint. Same goes forOR. I'm just confused at the moment as to which one has to return what but I'm proposing it anyway :D