Return early if rules are empty to avoid visiting elements

This is tested already in testPassesValidationWithEmptyRules
This commit is contained in:
Adrian Philipp 2018-04-12 17:36:24 +02:00
parent 568cae584b
commit b3791378fa

View File

@ -86,6 +86,12 @@ class DocumentValidator
if (null === $rules) { if (null === $rules) {
$rules = static::allRules(); $rules = static::allRules();
} }
if (true === is_array($rules) && 0 === count($rules)) {
// Skip validation if there are no rules
return [];
}
$typeInfo = $typeInfo ?: new TypeInfo($schema); $typeInfo = $typeInfo ?: new TypeInfo($schema);
$errors = static::visitUsingRules($schema, $typeInfo, $ast, $rules); $errors = static::visitUsingRules($schema, $typeInfo, $ast, $rules);
return $errors; return $errors;