This repository has been archived by the owner on Dec 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
optional and boolean api inconsistency #265
Comments
You're right. Unfortunately, changing either one of Let's keep this open for Faker 2.0. |
Excellent! Thanks :) |
The $faker->optional(40); // new optional method with percentage
$faker->optional(0.6); // old system Internally could be: public function optional($weight = 0.5, $default = null)
{
// case 1
if (ctype_digit($weight) && mt_rand(1, 100) <= $weight) {
return $this->generator;
}
// case 2
if ($weight > 0 && $weight < 1 && mt_rand() / mt_getrandmax() <= $weight) {
return $this->generator;
}
return new DefaultGenerator($default);
} Use cases
I can write a PR if this is ok for you. |
Great idea! I'd love a PR. |
Closed due to inactivity. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
It feels unintuitive to me that
optional
andboolean
use completely different input values.Shouldn't they both use percentages?
The text was updated successfully, but these errors were encountered: