From b59a774f9310f82423d5823f7e2a0e54372259e1 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 21 Nov 2014 09:49:35 +0100 Subject: [PATCH] [2.3] Remove possible call_user_func() --- Constraints/CallbackValidator.php | 4 +++- Constraints/ChoiceValidator.php | 9 ++++----- Constraints/TypeValidator.php | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Constraints/CallbackValidator.php b/Constraints/CallbackValidator.php index ca5a42bca..32b20e8a5 100644 --- a/Constraints/CallbackValidator.php +++ b/Constraints/CallbackValidator.php @@ -43,7 +43,9 @@ public function validate($object, Constraint $constraint) $methods = $constraint->methods; foreach ($methods as $method) { - if (is_array($method) || $method instanceof \Closure) { + if ($method instanceof \Closure) { + $method($object, $this->context); + } elseif (is_array($method)) { if (!is_callable($method)) { throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Callback constraint is not a valid callable', $method[0], $method[1])); } diff --git a/Constraints/ChoiceValidator.php b/Constraints/ChoiceValidator.php index 93f13c75d..0581d7da7 100644 --- a/Constraints/ChoiceValidator.php +++ b/Constraints/ChoiceValidator.php @@ -45,13 +45,12 @@ public function validate($value, Constraint $constraint) } if ($constraint->callback) { - if (is_callable(array($this->context->getClassName(), $constraint->callback))) { - $choices = call_user_func(array($this->context->getClassName(), $constraint->callback)); - } elseif (is_callable($constraint->callback)) { - $choices = call_user_func($constraint->callback); - } else { + if (!is_callable($choices = array($this->context->getClassName(), $constraint->callback)) + && !is_callable($choices = $constraint->callback) + ) { throw new ConstraintDefinitionException('The Choice constraint expects a valid callback'); } + $choices = call_user_func($choices); } else { $choices = $constraint->choices; } diff --git a/Constraints/TypeValidator.php b/Constraints/TypeValidator.php index b89b5cba1..979df4ec6 100644 --- a/Constraints/TypeValidator.php +++ b/Constraints/TypeValidator.php @@ -35,9 +35,9 @@ public function validate($value, Constraint $constraint) $isFunction = 'is_'.$type; $ctypeFunction = 'ctype_'.$type; - if (function_exists($isFunction) && call_user_func($isFunction, $value)) { + if (function_exists($isFunction) && $isFunction($value)) { return; - } elseif (function_exists($ctypeFunction) && call_user_func($ctypeFunction, $value)) { + } elseif (function_exists($ctypeFunction) && $ctypeFunction($value)) { return; } elseif ($value instanceof $constraint->type) { return;