NumberAnonymizer.php in General Data Protection Regulation 3.0.x
File
modules/anonymizer/src/Plugin/Anonymizer/NumberAnonymizer.php
View source
<?php
namespace Drupal\anonymizer\Plugin\Anonymizer;
use Drupal\anonymizer\Anonymizer\AnonymizerBase;
use Drupal\Core\Field\FieldItemListInterface;
use function str_repeat;
use function strlen;
class NumberAnonymizer extends AnonymizerBase {
public function anonymize($input, FieldItemListInterface $field = NULL) {
if ($length = strlen($input)) {
$generator = $this->faker
->generator();
$length = $generator
->numberBetween(1, $length);
return $generator
->numerify(str_repeat('#', $length));
}
return $input;
}
}