files("wordlists/{$method}") as $file) { $contents = array_filter(explode("\n", $storage->get($file))); $words->push(...$contents); } Cache::put($cache_key, $words, 60 * 5); return $words; } throw new \BadMethodCallException(); } /** * Create a random string of words in the provided format. * * Supported format keys: * - a: adjective, * - n: noun, * - p: preposition, and * - v: verb. */ public static function randomWords(string $format = 'an', $asArray = false): array|string { $words = []; foreach (str_split($format) as $type) { $words[] = match ($type) { 'a' => self::adjectives()->random(), 'n' => self::nouns()->random(), 'p' => self::prepositions()->random(), 'v' => self::verbs()->random(), default => NULL }; } if ($asArray) { return $words; } return implode(' ', $words); } }