From dc0616edafdd9aa0b309f11ceef73c9c2edefc49 Mon Sep 17 00:00:00 2001 From: Adrian Philipp Date: Thu, 12 Apr 2018 17:36:24 +0200 Subject: [PATCH] Return early if rules are empty to avoid visiting elements This is tested already in testPassesValidationWithEmptyRules --- src/Validator/DocumentValidator.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Validator/DocumentValidator.php b/src/Validator/DocumentValidator.php index 31b7649..0f85770 100644 --- a/src/Validator/DocumentValidator.php +++ b/src/Validator/DocumentValidator.php @@ -96,6 +96,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;