From f7e5b1c105dec980b3206c0b9bc7db735756b8d5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 18 May 2021 10:35:35 -0500 Subject: [PATCH] formatting --- src/Illuminate/Validation/Rules/Password.php | 26 ++++++++++++------- .../Validation/ValidationPasswordRuleTest.php | 8 +++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Illuminate/Validation/Rules/Password.php b/src/Illuminate/Validation/Rules/Password.php index db34c11c92e4..fb2a64f22e53 100644 --- a/src/Illuminate/Validation/Rules/Password.php +++ b/src/Illuminate/Validation/Rules/Password.php @@ -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 */ @@ -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 */ @@ -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 */ @@ -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 */ diff --git a/tests/Validation/ValidationPasswordRuleTest.php b/tests/Validation/ValidationPasswordRuleTest.php index bdd7edf65ec9..5d16de98f224 100644 --- a/tests/Validation/ValidationPasswordRuleTest.php +++ b/tests/Validation/ValidationPasswordRuleTest.php @@ -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; }); @@ -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()); @@ -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)