Skip to content

Commit 07255a8

Browse files
committed
minor #12529 [2.3] Remove possible call_user_func() (nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- [2.3] Remove possible call_user_func() | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Merging this in 2.3 enhances performance a bit, but more importantly will ease future merges into 3.0. Commits ------- fad7aba [2.3] Remove possible call_user_func()
2 parents 663b799 + b59a774 commit 07255a8

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

Constraints/CallbackValidator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public function validate($object, Constraint $constraint)
4343
$methods = $constraint->methods;
4444

4545
foreach ($methods as $method) {
46-
if (is_array($method) || $method instanceof \Closure) {
46+
if ($method instanceof \Closure) {
47+
$method($object, $this->context);
48+
} elseif (is_array($method)) {
4749
if (!is_callable($method)) {
4850
throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Callback constraint is not a valid callable', $method[0], $method[1]));
4951
}

Constraints/ChoiceValidator.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ public function validate($value, Constraint $constraint)
4545
}
4646

4747
if ($constraint->callback) {
48-
if (is_callable(array($this->context->getClassName(), $constraint->callback))) {
49-
$choices = call_user_func(array($this->context->getClassName(), $constraint->callback));
50-
} elseif (is_callable($constraint->callback)) {
51-
$choices = call_user_func($constraint->callback);
52-
} else {
48+
if (!is_callable($choices = array($this->context->getClassName(), $constraint->callback))
49+
&& !is_callable($choices = $constraint->callback)
50+
) {
5351
throw new ConstraintDefinitionException('The Choice constraint expects a valid callback');
5452
}
53+
$choices = call_user_func($choices);
5554
} else {
5655
$choices = $constraint->choices;
5756
}

Constraints/TypeValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public function validate($value, Constraint $constraint)
3535
$isFunction = 'is_'.$type;
3636
$ctypeFunction = 'ctype_'.$type;
3737

38-
if (function_exists($isFunction) && call_user_func($isFunction, $value)) {
38+
if (function_exists($isFunction) && $isFunction($value)) {
3939
return;
40-
} elseif (function_exists($ctypeFunction) && call_user_func($ctypeFunction, $value)) {
40+
} elseif (function_exists($ctypeFunction) && $ctypeFunction($value)) {
4141
return;
4242
} elseif ($value instanceof $constraint->type) {
4343
return;

0 commit comments

Comments
 (0)