Skip to content

Commit

Permalink
Fix ExcludeIf regression to use Closure over is_callable() (#41969)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonSurowiec authored Apr 14, 2022
1 parent 756276c commit e5775a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Illuminate/Validation/Rules/ExcludeIf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Validation\Rules;

use Closure;
use InvalidArgumentException;

class ExcludeIf
Expand All @@ -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.');
Expand Down
2 changes: 1 addition & 1 deletion tests/Validation/ValidationExcludeIfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit e5775a7

Please sign in to comment.