Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Fix ExcludeIf regression to use Closure over is_callable() #41969

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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