From 6f957f551e8b5a83b9a1534ecaf3f0aefe87c4e2 Mon Sep 17 00:00:00 2001 From: Brandon Surowiec Date: Wed, 13 Apr 2022 23:53:30 -0400 Subject: [PATCH] Fix ExcludeIf regression to use Closure over is_callable() --- src/Illuminate/Validation/Rules/ExcludeIf.php | 5 +++-- tests/Validation/ValidationExcludeIfTest.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Validation/Rules/ExcludeIf.php b/src/Illuminate/Validation/Rules/ExcludeIf.php index e72f35e5766d..9a53e6f24815 100644 --- a/src/Illuminate/Validation/Rules/ExcludeIf.php +++ b/src/Illuminate/Validation/Rules/ExcludeIf.php @@ -2,6 +2,7 @@ namespace Illuminate\Validation\Rules; +use Closure; use InvalidArgumentException; class ExcludeIf @@ -16,14 +17,14 @@ class ExcludeIf /** * Create a new exclude validation rule based on a condition. * - * @param callable|bool $condition + * @param \Closure|bool $condition * @return void * * @throws \InvalidArgumentException */ public function __construct($condition) { - if (is_callable($condition) || is_bool($condition)) { + if ($condition instanceof Closure || is_bool($condition)) { $this->condition = $condition; } else { throw new InvalidArgumentException('The provided condition must be a callable or boolean.'); diff --git a/tests/Validation/ValidationExcludeIfTest.php b/tests/Validation/ValidationExcludeIfTest.php index 4f68623740ce..51879a86e1a5 100644 --- a/tests/Validation/ValidationExcludeIfTest.php +++ b/tests/Validation/ValidationExcludeIfTest.php @@ -39,7 +39,7 @@ public function testItOnlyCallableAndBooleanAreAcceptableArgumentsOfTheRule() new ExcludeIf(true); new ExcludeIf(fn () => true); - foreach ([1, 1.1, 'foobar', new stdClass] as $condition) { + foreach ([1, 1.1, 'phpinfo', new stdClass] as $condition) { try { new ExcludeIf($condition); $this->fail('The ExcludeIf constructor must not accept '.gettype($condition));