PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Faker/Provider/Address.php

https://github.com/gobb/Faker
PHP | 121 lines | 70 code | 18 blank | 33 comment | 0 complexity | f57357a3488b302f3d76645b19ea3be3 MD5 | raw file
  1. <?php
  2. namespace Faker\Provider;
  3. class Address extends \Faker\Provider\Base
  4. {
  5. protected static $citySuffix = array('Ville');
  6. protected static $streetSuffix = array('Street');
  7. protected static $cityFormats = array(
  8. '{{firstName}}{{citySuffix}}',
  9. );
  10. protected static $streetNameFormats = array(
  11. '{{lastName}} {{streetSuffix}}'
  12. );
  13. protected static $streetAddressFormats = array(
  14. '{{buildingNumber}} {{streetName}}'
  15. );
  16. protected static $addressFormats = array(
  17. '{{streetAddress}} {{postcode}} {{city}}',
  18. );
  19. protected static $buildingNumber = array('##');
  20. protected static $postcode = array('#####');
  21. protected static $country = array();
  22. /**
  23. * @example 'town'
  24. */
  25. public static function citySuffix()
  26. {
  27. return static::randomElement(static::$citySuffix);
  28. }
  29. /**
  30. * @example 'Avenue'
  31. */
  32. public static function streetSuffix()
  33. {
  34. return static::randomElement(static::$streetSuffix);
  35. }
  36. /**
  37. * @example '791'
  38. */
  39. public static function buildingNumber()
  40. {
  41. return static::numerify(static::randomElement(static::$buildingNumber));
  42. }
  43. /**
  44. * @example 'Sashabury'
  45. */
  46. public function city()
  47. {
  48. $format = static::randomElement(static::$cityFormats);
  49. return $this->generator->parse($format);
  50. }
  51. /**
  52. * @example 'Crist Parks'
  53. */
  54. public function streetName()
  55. {
  56. $format = static::randomElement(static::$streetNameFormats);
  57. return $this->generator->parse($format);
  58. }
  59. /**
  60. * @example '791 Crist Parks'
  61. */
  62. public function streetAddress()
  63. {
  64. $format = static::randomElement(static::$streetAddressFormats);
  65. return $this->generator->parse($format);
  66. }
  67. /**
  68. * @example 86039-9874
  69. */
  70. public static function postcode()
  71. {
  72. return static::toUpper(static::bothify(static::randomElement(static::$postcode)));
  73. }
  74. /**
  75. * @example '791 Crist Parks, Sashabury, IL 86039-9874'
  76. */
  77. public function address()
  78. {
  79. $format = static::randomElement(static::$addressFormats);
  80. return $this->generator->parse($format);
  81. }
  82. /**
  83. * @example 'Japan'
  84. */
  85. public static function country()
  86. {
  87. return static::randomElement(static::$country);
  88. }
  89. /**
  90. * @example '77.147489'
  91. */
  92. public static function latitude()
  93. {
  94. return number_format(mt_rand(-90000000, 90000000)/1000000, 6);
  95. }
  96. /**
  97. * @example '86.211205'
  98. */
  99. public static function longitude()
  100. {
  101. return number_format(mt_rand(-180000000, 180000000)/1000000, 6);
  102. }
  103. }