From d83c009b28108adff94696cc252162d962b594f4 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Sat, 3 Jun 2017 14:11:13 +0200 Subject: [PATCH] TASK: taming complexity --- .../Validator/SettingsValidator.php | 58 ++++++++++++------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/Classes/Validation/Validator/SettingsValidator.php b/Classes/Validation/Validator/SettingsValidator.php index 4a87bd9..c10655f 100644 --- a/Classes/Validation/Validator/SettingsValidator.php +++ b/Classes/Validation/Validator/SettingsValidator.php @@ -85,6 +85,41 @@ class SettingsValidator extends AbstractValidator ); } + $config = $this->getConfigForName($name); + + foreach ($config as $validatorConfig) { + $validator = $this->validatorResolver->createValidator( + $validatorConfig['validator'], + $validatorConfig['options'] + ); + + if (! $validator) { + throw new InvalidValidationConfigurationException( + sprintf( + 'Validator could not be resolved: "%s" Check your Validation.yaml', + $validatorConfig['validator'] + ), + 1402326139 + ); + } + + if (isset($validatorConfig['property'])) { + $this->result->forProperty($validatorConfig['property'])->merge( + $validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])) + ); + } else { + $this->result->merge($validator->validate($value)); + } + } + } + + /** + * @param $name + * + * @return array + */ + protected function getConfigForName($name): array + { $config = []; if (isset($this->validations[$name]['self'])) { foreach ($this->validations[$name]['self'] as $validator => &$validation) { @@ -109,27 +144,6 @@ class SettingsValidator extends AbstractValidator } } } - - foreach ($config as $validatorConfig) { - $validator = $this->validatorResolver->createValidator( - $validatorConfig['validator'], - $validatorConfig['options'] - ); - - if (! $validator) { - throw new InvalidValidationConfigurationException( - 'Validator could not be resolved: ' . $validatorConfig['validator'] . '. Check your Validation.yaml', - 1402326139 - ); - } - - if (isset($validatorConfig['property'])) { - $this->result->forProperty($validatorConfig['property'])->merge( - $validator->validate(ObjectAccess::getPropertyPath($value, $validatorConfig['property'])) - ); - } else { - $this->result->merge($validator->validate($value)); - } - } + return $config; } }