Skip to content

Commit 5b7b639

Browse files
authored
Refactor email generation to use Randomizer (#37)
Updated the email generation method to use a Randomizer instance for better randomness.
1 parent 4d3d3fe commit 5b7b639

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

content/1.getting-started/7.custom-extension.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ class CustomEmailExtension extends Extension
1313
{
1414
public function generateRandomEmail(string $domainName): mixed
1515
{
16-
$localPart = strtolower(bin2hex(random_bytes(4)));
16+
$randomBytes = $this->randomizer->getBytes(4);
17+
$localPart = strtolower(bin2hex($randomBytes));
1718
return $localPart . '@' . $domainName;
1819
}
1920
}
2021
```
2122

23+
`$this->randomizer` is the PHP 8 [Randomizer instance](https://www.php.net/manual/en/class.random-randomizer.php)
24+
2225
You'll also need to load your extension into Faker
2326
```php
2427
faker()->resolveExtensions([CustomEmailExtension::class])

0 commit comments

Comments
 (0)