1
0
mirror of https://github.com/fzaninotto/Faker.git synced 2025-04-14 12:32:03 +02:00

Make boolean() provider more controllable

This commit is contained in:
Francois Zaninotto 2011-10-30 13:21:35 +01:00
parent e5e3713e66
commit b41c916f63
3 changed files with 7 additions and 4 deletions

View File

@ -142,7 +142,7 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle
### `Faker\Provider\Miscellaneous`
boolean // true
boolean($chanceOfGettingTrue = 50) // true
md5 // 'de99a620c50f2990e87144735cd357e7'
sha1 // 'f08e7f04ca1a413807ebc47551a40a20a0b4de5c'
sha256 // '0061e4c60dac5c1d82db0135a42e00c89ae3a333e7c26485321f24348c7e98a5'

View File

@ -14,7 +14,7 @@ class Documentor
public function getFormatters()
{
$formatters = array();
$providers = $this->generator->getProviders();
$providers = array_reverse($this->generator->getProviders());
$providers[]= new \Faker\Provider\Base($this->generator);
foreach ($providers as $provider) {
$providerClass = get_class($provider);

View File

@ -6,11 +6,14 @@ class Miscellaneous extends \Faker\Provider\Base
{
/**
* Return a boolean, true or false
*
* @param integer $chanceOfGettingTrue Between 0 (always get false) and 100 (always get true).
* @example true
*/
public static function boolean()
public static function boolean($chanceOfGettingTrue = 50)
{
return mt_rand(0, 1) == 0 ? true: false;
return mt_rand(0, 100) <= $chanceOfGettingTrue ? true: false;
}
/**