From b3791378fa35e307a74604fd7df2f6029d4768ca 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 3efd992..201a850 100644 --- a/src/Validator/DocumentValidator.php +++ b/src/Validator/DocumentValidator.php @@ -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;