isEmpty(); return empty($string); } /** * Check if a string is null or whitespace. * * @param IString|string|null $string String to check for whitespace. * @return bool true if the string is whitespace, false if not. */ public static function nullOrWhitespace(IString|string|null $string): bool { if($string === null) return true; return empty(trim((string)$string)); } /** * Generates a random string of user specified length. * * @param int $length Desired length of the string. * @param string $chars Set of characters to pick from. Default set contains the alphabet in upper- and lowercase and numbers 0 thru 9. * @return string The generated string. */ public static function random(int $length, string $chars = self::RANDOM_CHARS): string { if($length < 1) throw new InvalidArgumentException('$length must be at least 1.'); if($chars === '') throw new InvalidArgumentException('$chars may not be empty.'); $string = ''; $count = strlen($chars) - 1; while($length-- > 0) $string .= $chars[random_int(0, $count)]; return $string; } }