PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Faker/Provider/Miscellaneous.php

https://github.com/gobb/Faker
PHP | 68 lines | 35 code | 9 blank | 24 comment | 0 complexity | c056dd20cfab0fab1b03894ab372bdfe MD5 | raw file
  1. <?php
  2. namespace Faker\Provider;
  3. class Miscellaneous extends \Faker\Provider\Base
  4. {
  5. protected static $languageCode = array('cn', 'de', 'en', 'es', 'fr', 'it', 'pt', 'ru');
  6. protected static $countryCode = array('CA', 'CN', 'DE', 'ES', 'FR', 'IE', 'IN', 'IT', 'MX', 'PT', 'RU', 'UK', 'US');
  7. /**
  8. * Return a boolean, true or false
  9. *
  10. * @param integer $chanceOfGettingTrue Between 0 (always get false) and 100 (always get true).
  11. * @example true
  12. */
  13. public static function boolean($chanceOfGettingTrue = 50)
  14. {
  15. return mt_rand(1, 100) <= $chanceOfGettingTrue ? true: false;
  16. }
  17. /**
  18. * @example 'cfcd208495d565ef66e7dff9f98764da'
  19. */
  20. public static function md5()
  21. {
  22. return md5(mt_rand());
  23. }
  24. /**
  25. * @example 'b5d86317c2a144cd04d0d7c03b2b02666fafadf2'
  26. */
  27. public static function sha1()
  28. {
  29. return sha1(mt_rand());
  30. }
  31. /**
  32. * @example '85086017559ccc40638fcde2fecaf295e0de7ca51b7517b6aebeaaf75b4d4654'
  33. */
  34. public static function sha256()
  35. {
  36. return hash('sha256', mt_rand());
  37. }
  38. /**
  39. * @example 'fr_FR'
  40. */
  41. public function locale()
  42. {
  43. return $this->languageCode() . '_' . $this->countryCode();
  44. }
  45. /**
  46. * @example 'FR'
  47. */
  48. public static function countryCode()
  49. {
  50. return static::randomElement(static::$countryCode);
  51. }
  52. /**
  53. * @example 'fr'
  54. */
  55. public static function languageCode()
  56. {
  57. return static::randomElement(static::$languageCode);
  58. }
  59. }