Repository: laravel/framework
File: src/Illuminate/Validation/Rules/Password.php (PHP)

Code before:
     * @return $this
     */
    public function rules($rules)
    {
        $this->customRules = Arr::wrap($rules);

        return $this;
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $this->messages = [];

        if (! $this->required && ! $this->sometimes && ($this->data === null || ! Arr::has($this->data, $attribute))) {
            return true;
        }

        if ($this->validator && $this->validator->hasRule($attribute, ['Nullable'])) {
            if ($value === null || (is_string($value) && trim($value) === '')) {
                return true;
            }
        }

        $validator = Validator::make(
            $this->data,
            [$attribute => [
                ...($this->required ? ['required'] : []),
                ...($this->sometimes ? ['sometimes'] : []),
                'string',
                'min:'.$this->min,
                ...($this->max ? ['max:'.$this->max] : []),
                ...$this->customRules,
            ]],
            $this->validator->customMessages,
            $this->validator->customAttributes
        )->after(function ($validator) use ($attribute, $value) {
            if (! is_string($value)) {
                return;
            }

            if ($this->mixedCase && ! preg_match('/(\p{Ll}+.*\p{Lu})|(\p{Lu}+.*\p{Ll})/u', $value)) {
                $validator->addFailure($attribute, 'password.mixed');
            }


Review comment (refactor):
You can replace this `if` condition with:

```php
if (blank($value)) {
```

The `blank()` helper will return `true` for all the cases you are checking against.

Code after:
     * @return $this
     */
    public function rules($rules)
    {
        $this->customRules = Arr::wrap($rules);

        return $this;
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $this->messages = [];

        if (! $this->required && ! $this->sometimes && ! Arr::has($this->data ?? [], $attribute)) {
            return true;
        }

        if (blank($value) && ! $this->required && $this->validator?->hasRule($attribute, ['Nullable'])) {
            return true;
        }

        $validator = Validator::make(
            $this->data,
            [$attribute => [
                ...($this->required ? ['required'] : []),
                ...($this->sometimes ? ['sometimes'] : []),
                'string',
                'min:'.$this->min,
                ...($this->max ? ['max:'.$this->max] : []),
                ...$this->customRules,
            ]],
            $this->validator->customMessages,
            $this->validator->customAttributes
        )->after(function ($validator) use ($attribute, $value) {
            if (! is_string($value)) {
                return;
            }

            if ($this->mixedCase && ! preg_match('/(\p{Ll}+.*\p{Lu})|(\p{Lu}+.*\p{Ll})/u', $value)) {
                $validator->addFailure($attribute, 'password.mixed');
            }

            if ($this->letters && ! preg_match('/\pL/u', $value)) {
                $validator->addFailure($attribute, 'password.letters');