Skip to content
Open
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
51 changes: 50 additions & 1 deletion src/Extracting/ParsesValidationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,55 @@ protected function parseRule($rule, array &$parameterData, bool $independentOnly
return true;
}


if ($rule instanceof \Illuminate\Validation\Rules\Password) {
// no getters available on Password class, so we use Reflection to extract protected attributes
$passwordAttrs = [];
$reflection = new ReflectionClass($rule);
foreach ($reflection->getProperties() as $property) {
if ($property->isStatic()) {
continue;
}
$property->setAccessible(true);
$passwordAttrs[$property->getName()] = $property->getValue($rule);
}

$min = $passwordAttrs['min'] ?? null;
$max = $passwordAttrs['max'] ?? null;
$letters = $passwordAttrs['letters'] ?? false;
$mixedCase = $passwordAttrs['mixedCase'] ?? false;
$numbers = $passwordAttrs['numbers'] ?? false;
$symbols = $passwordAttrs['symbols'] ?? false;

if (!empty($min)) {
$parameterData['description'] .= ' ' . $this->getDescription('min', [':min' => $min]);
}
if (!empty($max)) {
$parameterData['description'] .= ' ' . $this->getDescription('max', [':max' => $max]);
}
if ($letters) {
$parameterData['description'] .= ' ' . $this->getDescription('password.letters');
}
if ($mixedCase) {
$parameterData['description'] .= ' ' . $this->getDescription('password.mixed');
}
if ($numbers) {
$parameterData['description'] .= ' ' . $this->getDescription('password.numbers');
}
if ($symbols) {
$parameterData['description'] .= ' ' . $this->getDescription('password.symbols');
}

$parameterData['setter'] = fn () => Str::password(
length: rand($min ?? 10, $max ?? 14),
letters: $letters,
numbers: $numbers,
symbols: $symbols,
);

return true;
}

if ($rule instanceof Rule || $rule instanceof ValidationRule) {
if (method_exists($rule, 'invokable')) {
// Laravel wraps InvokableRule instances in an InvokableValidationRule class,
Expand Down Expand Up @@ -847,4 +896,4 @@ protected function shouldCastUserExample()
{
return false;
}
}
}
Loading