-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91730b5
commit 3b7dec5
Showing
5 changed files
with
50 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,35 +14,27 @@ | |
|
||
class Email implements AnonymizerInterface | ||
{ | ||
private const PHRASE = '%1-anonymous-%[email protected]'; | ||
private const PREFIX_LENGTH = 3; | ||
private const SUFFIX_LENGTH = 2; | ||
public function __construct(private Random $mathRandom) {} | ||
|
||
/** | ||
* @var Random | ||
* @throws LocalizedException | ||
*/ | ||
private Random $mathRandom; | ||
|
||
public function __construct( | ||
Random $mathRandom | ||
) { | ||
$this->mathRandom = $mathRandom; | ||
public function anonymize($value): ?string | ||
{ | ||
return $value ? $this->createPhrase()->render() : null; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
* @throws LocalizedException | ||
*/ | ||
public function anonymize($value): ?string | ||
private function createPhrase(): Phrase | ||
{ | ||
return $value | ||
? (new Phrase( | ||
self::PHRASE, | ||
[ | ||
$this->mathRandom->getRandomString(self::PREFIX_LENGTH, Random::CHARS_LOWERS), | ||
$this->mathRandom->getRandomString(self::SUFFIX_LENGTH, Random::CHARS_LOWERS), | ||
] | ||
))->render() | ||
: null; | ||
return new Phrase( | ||
'%1-anonymous-%[email protected]', | ||
[ | ||
$this->mathRandom->getRandomString(3, Random::CHARS_LOWERS), | ||
$this->mathRandom->getRandomString(2, Random::CHARS_LOWERS) | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters