You are here

public function NumberAnonymizer::anonymize in General Data Protection Regulation 3.0.x

Same name and namespace in other branches
  1. 8.2 modules/anonymizer/src/Plugin/Anonymizer/NumberAnonymizer.php \Drupal\anonymizer\Plugin\Anonymizer\NumberAnonymizer::anonymize()
  2. 8 modules/anonymizer/src/Plugin/Anonymizer/NumberAnonymizer.php \Drupal\anonymizer\Plugin\Anonymizer\NumberAnonymizer::anonymize()

Throws

\RuntimeException

Overrides AnonymizerInterface::anonymize

File

modules/anonymizer/src/Plugin/Anonymizer/NumberAnonymizer.php, line 28

Class

NumberAnonymizer
Class NumberAnonymizer.

Namespace

Drupal\anonymizer\Plugin\Anonymizer

Code

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;
}