You are here

public function Generator::words in Style Guide 8

Same name and namespace in other branches
  1. 2.x src/Generator.php \Drupal\styleguide\Generator::words()

Return a random word or words.

Parameters

int $size: The number of words to return.

string $case: A string indicating the case to return. This is the name of a PHP function. options are 'ucfirst', 'ucwords', 'strtoupper', and 'strtolower'. Defaults to return strtolower().

Overrides GeneratorInterface::words

3 calls to Generator::words()
Generator::links in src/Generator.php
Generate a array of random links.
Generator::ulLinks in src/Generator.php
Generate a links array for theme_links.
Generator::wordList in src/Generator.php
Return a simple array of words.

File

src/Generator.php, line 71

Class

Generator
Class Generator.

Namespace

Drupal\styleguide

Code

public function words($size = 1, $case = 'strtolower') {
  $words = [];
  for ($i = 0; $i < $size; $i++) {
    $words[] = $this->random
      ->word(rand(4, 12));
  }
  $words = implode(' ', $words);
  $functions = [
    'ucfirst',
    'ucwords',
    'strtoupper',
    'strtolower',
  ];
  if (!is_null($case) && function_exists($case) && in_array($case, $functions)) {
    $words = $case($words);
  }
  return $words;
}