Skip to content

Commit b764d37

Browse files
travoltronmpociot
authored andcommitted
Update AbstractGenerator.php (mpociot#157)
The built in faker->randomNumber freaks out on `digits:10`, commonly seen on phone number validation. This is directionally where I'd send it, but maybe not the cleanest execution. But the basic idea is that if the length of digits being randomized is less than 9, proceed as previous, greater than that, use mt_rand() from 1,000,000,000 up to mt_randmax(), which incidentally, is still a 10 digit number... and then take the substr starting at pos{0}, and ending at the desired digit length. Maybe a specific regex is in order?
1 parent d4ca5fc commit b764d37

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Mpociot/ApiDoc/Generators/AbstractGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ protected function parseRule($rule, $ruleName, &$attributeData, $seed)
308308
case 'digits':
309309
$attributeData['type'] = 'numeric';
310310
$attributeData['description'][] = Description::parse($rule)->with($parameters)->getDescription();
311-
$attributeData['value'] = $faker->randomNumber($parameters[0], true);
311+
$attributeData['value'] = ($parameters[0] < 9) ? $faker->randomNumber($parameters[0], true) : substr(mt_rand(100000000, mt_getrandmax()), 0, $parameters[0]);
312312
break;
313313
case 'digits_between':
314314
$attributeData['type'] = 'numeric';

0 commit comments

Comments
 (0)