Merge pull request #270 from adri/allow-validation-to-be-skipped

Validation > Performance > Return early if rules are empty to avoid visiting elements
This commit is contained in:
Vladimir Razuvaev 2018-04-13 13:18:04 +08:00 committed by GitHub
commit 4418f4f975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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