Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 18, 2021
1 parent b42be88 commit f7e5b1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
26 changes: 16 additions & 10 deletions src/Illuminate/Validation/Rules/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Password implements Rule, DataAwareRule
protected $messages = [];

/**
* The callback to be used for the Password's default rules.
* The callback that will generate the "default" version of the password rule.
*
* @var string|array|callable|null
*/
Expand All @@ -94,22 +94,28 @@ public function __construct($min)
}

/**
* Set the default callback to be used for determining the Password's default rules.
* Set the default callback to be used for determining a password's default rules.
*
* @param static|callable $callback
* @return void
* If no arguments are passed, the default password rule configuration will be returned.
*
* @param static|callable|null $callback
* @return static|null
*/
public static function defaultUsing($callback)
public static function defaults($callback = null)
{
if (! is_callable($callback) && ! $callback instanceof self) {
throw new InvalidArgumentException('$callback should either be callable or an instance of '.self::class);
if (is_null($callback)) {
return static::default();
}

if (! is_callable($callback) && ! $callback instanceof static) {
throw new InvalidArgumentException('The given callback should be callable or an instance of '.static::class);
}

static::$defaultCallback = $callback;
}

/**
* Get Password's default rules.
* Get the default configuration of the password rule.
*
* @return static
*/
Expand All @@ -121,7 +127,7 @@ public static function default()
}

/**
* Get Password's default rules as required.
* Get the default configuration of the password rule and mark the field as required.
*
* @return array
*/
Expand All @@ -131,7 +137,7 @@ public static function required()
}

/**
* Get Password's default rules as sometimes.
* Get the default configuration of the password rule and mark the field as sometimes being required.
*
* @return array
*/
Expand Down
8 changes: 4 additions & 4 deletions tests/Validation/ValidationPasswordRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function testItCanSetDefaultUsing()
$password = Password::min(3);
$password2 = Password::min(2)->mixedCase();

Password::defaultUsing(function () use ($password) {
Password::defaults(function () use ($password) {
return $password;
});

Expand All @@ -198,7 +198,7 @@ public function testItCanSetDefaultUsing()
$this->assertSame(['required', $password], Password::required());
$this->assertSame(['sometimes', $password], Password::sometimes());

Password::defaultUsing($password2);
Password::defaults($password2);
$this->passes(Password::default(), ['Nn', 'Mn', 'âA']);
$this->assertSame($password2, Password::default());
$this->assertSame(['required', $password2], Password::required());
Expand All @@ -208,9 +208,9 @@ public function testItCanSetDefaultUsing()
public function testItCannotSetDefaultUsingGivenString()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('$callback should either be callable or an instance of '.Password::class);
$this->expectExceptionMessage('given callback should be callable');

Password::defaultUsing('required|password');
Password::defaults('required|password');
}

protected function passes($rule, $values)
Expand Down

0 comments on commit f7e5b1c

Please sign in to comment.