PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/fakerphp/faker/src/Faker/Provider/el_GR/PhoneNumber.php

https://gitlab.com/madwanz64/laravel
PHP | 324 lines | 166 code | 31 blank | 127 comment | 0 complexity | a32b4e2744b06b811738144c970bda18 MD5 | raw file
  1. <?php
  2. namespace Faker\Provider\el_GR;
  3. /**
  4. * @see https://en.wikipedia.org/wiki/Telephone_numbers_in_Greece
  5. * @see https://github.com/giggsey/libphonenumber-for-php/blob/master/src/data/PhoneNumberMetadata_GR.php
  6. */
  7. class PhoneNumber extends \Faker\Provider\PhoneNumber
  8. {
  9. protected static $internationalCallPrefixes = ['', '+30'];
  10. protected static $formats = [
  11. '{{fixedLineNumber}}',
  12. '{{mobileNumber}}',
  13. '{{personalNumber}}',
  14. '{{tollFreeNumber}}',
  15. '{{sharedCostNumber}}',
  16. '{{premiumRateNumber}}',
  17. ];
  18. protected static $areaCodes = [
  19. // Zone 22: Central Greece and the Aegean Islands
  20. 2221, 2222, 2223, 2224, 2226, 2227, 2228, 2229,
  21. 2231, 2232, 2233, 2234, 2235, 2236, 2237, 2238,
  22. 2241, 2242, 2243, 2244, 2245, 2246, 2247,
  23. 2251, 2252, 2253, 2254,
  24. 2261, 2262, 2263, 2264, 2265, 2266, 2267, 2268,
  25. 2271, 2272, 2273, 2274, 2275,
  26. 2281, 2282, 2283, 2284, 2285, 2286, 2287, 2288, 2289,
  27. 2291, 2292, 2293, 2294, 2295, 2296, 2297, 2298, 2299,
  28. // Zone 23: Central Macedonia and Florina
  29. 231,
  30. 2321, 2322, 2323, 2324, 2325, 2327,
  31. 2331, 2332, 2333,
  32. 2341, 2343,
  33. 2351, 2352, 2353,
  34. 2371, 2372, 2373, 2374, 2375, 2376, 2377,
  35. 2381, 2382, 2384, 2385, 2386,
  36. 2391, 2392, 2393, 2394, 2395, 2396, 2397, 2399,
  37. // Zone 24: Thessaly and West Macedonia (excluding Florina)
  38. 241,
  39. 2421, 2422, 2423, 2424, 2425, 2426, 2427, 2428,
  40. 2431, 2432, 2433, 2434,
  41. 2441, 2443, 2444, 2445,
  42. 2461, 2462, 2463, 2464, 2465, 2467, 2468,
  43. 2491, 2492, 2493, 2494, 2495,
  44. // Zone 25: East Macedonia and Thrace
  45. 251,
  46. 2521, 2522, 2523, 2524,
  47. 2531, 2532, 2533, 2534, 2535,
  48. 2541, 2542, 2544,
  49. 2591, 2592, 2593, 2594,
  50. 2551, 2552, 2553, 2554, 2555, 2556,
  51. // Zone 26: West Greece, Ionian Island and Epirus
  52. 261,
  53. 2621, 2622, 2623, 2624, 2625, 2626,
  54. 2631, 2632, 2634, 2635,
  55. 2661, 2662, 2663, 2664, 2665, 2666,
  56. 2691, 2692, 2693, 2694, 2695, 2696,
  57. 2641, 2642, 2643, 2644, 2645, 2646, 2647,
  58. 2651, 2653, 2654, 2655, 2656, 2657, 2658, 2659,
  59. 2671, 2674,
  60. 2681, 2682, 2683, 2684, 2685,
  61. // Zone 27: Peloponnese and Kythera
  62. 271,
  63. 2721, 2722, 2723, 2724, 2725,
  64. 2731, 2732, 2733, 2734, 2735, 2736,
  65. 2741, 2742, 2743, 2744, 2745, 2746, 2747,
  66. 2751, 2752, 2753, 2754, 2755, 2757,
  67. 2761, 2763, 2765,
  68. 2791, 2792, 2795, 2797,
  69. // Zone 28: Crete
  70. 281,
  71. 2821, 2822, 2823, 2824, 2825,
  72. 2831, 2832, 2833, 2834,
  73. 2841, 2842, 2843, 2844,
  74. 2891, 2892, 2893, 2894, 2895, 2897,
  75. ];
  76. protected static $fixedLineFormats = [
  77. '{{internationalCodePrefix}}21########',
  78. '{{internationalCodePrefix}} 21# ### ####',
  79. '{{internationalCodePrefix}}{{areaCode}}######',
  80. '{{internationalCodePrefix}} {{areaCode}} ######',
  81. ];
  82. protected static $mobileCodes = [
  83. 685, 687, 688, 689,
  84. 690, 691, 693, 694, 695, 696, 697, 698, 699,
  85. ];
  86. protected static $mobileFormats = [
  87. '{{internationalCodePrefix}}{{mobileCode}}#######',
  88. '{{internationalCodePrefix}} {{mobileCode}} ### ####',
  89. ];
  90. protected static $personalFormats = [
  91. '{{internationalCodePrefix}}70########',
  92. '{{internationalCodePrefix}} 70 #### ####',
  93. ];
  94. protected static $tollFreeFormats = [
  95. '{{internationalCodePrefix}}800#######',
  96. '{{internationalCodePrefix}} 800 ### ####',
  97. ];
  98. protected static $sharedCostCodes = [801, 806, 812, 825, 850, 875];
  99. protected static $sharedCostFormats = [
  100. '{{internationalCodePrefix}}{{sharedCostCode}}#######',
  101. '{{internationalCodePrefix}} {{sharedCostCode}} ### ####',
  102. ];
  103. protected static $premiumRateCodes = [901, 909];
  104. protected static $premiumRateFormats = [
  105. '{{internationalCodePrefix}}{{premiumRateCode}}#######',
  106. '{{internationalCodePrefix}} {{premiumRateCode}} ### ####',
  107. ];
  108. /**
  109. * Generate a country calling code prefix.
  110. *
  111. * @example Prefix an empty string: ''
  112. * @example Prefix the country calling code: '+30'
  113. *
  114. * @internal Used to generate phone numbers with or without prefixes.
  115. *
  116. * @return string
  117. */
  118. public static function internationalCodePrefix()
  119. {
  120. return static::randomElement(static::$internationalCallPrefixes);
  121. }
  122. /**
  123. * Generate an area code for a fixed line number.
  124. *
  125. * Doesn't include codes for Greater Athens Metropolitan Area (21#) because
  126. * this zone uses 3 digits, and phone numbers have a different formatting.
  127. *
  128. * Area codes in all the other zones use 4 digits.
  129. * The capital of each zone uses 3 digits and the 4th digit can be any number.
  130. * The other areas in each zone use 4 digits, but not every number is valid for the 4th digit.
  131. *
  132. * @example Thessaloniki has code '231', so '2310' and '2313' are valid.
  133. * @example Serres has code '232', but '2326', '2328' and '2329' are not valid.
  134. *
  135. * @return string
  136. */
  137. public static function areaCode()
  138. {
  139. return static::numerify(
  140. str_pad(static::randomElement(static::$areaCodes), 4, '#')
  141. );
  142. }
  143. /**
  144. * Generate a fixed line number.
  145. *
  146. * Numbers can be generated with or without the international code prefix.
  147. * Numbers can be generated with or without spaces between their parts.
  148. * Numbers in Athens use a 3-digit area code, and can be formatted as 21# ### ####.
  149. * Numbers in other areas use a 4-digit area code, and can be formatted as 2### ### ###.
  150. *
  151. * @example A number in Athens: '2101234567'
  152. * @example A number in Thessaloniki: '2310123456'
  153. * @example A number with spaces in Athens: '210 123 4567'
  154. * @example A number with spaces in Thessaloniki: '2310 123 456'
  155. * @example A number with international code prefix: '+302101234567'
  156. * @example A number with international code prefix and spaces: '+30 2310 123 456'
  157. *
  158. * @return string
  159. */
  160. public function fixedLineNumber()
  161. {
  162. return ltrim(static::numerify($this->generator->parse(
  163. static::randomElement(static::$fixedLineFormats)
  164. )));
  165. }
  166. /**
  167. * Generate a code for a mobile number.
  168. *
  169. * @internal Used to generate mobile numbers.
  170. *
  171. * @return string
  172. */
  173. public static function mobileCode()
  174. {
  175. return static::randomElement(static::$mobileCodes);
  176. }
  177. /**
  178. * Generate a mobile number.
  179. *
  180. * @example A mobile number: '6901234567'
  181. * @example A mobile number with spaces: '690 123 4567'
  182. * @example A mobile number with international code prefix: '+306901234567'
  183. * @example A mobile number with international code prefix and spaces: '+30 690 123 4567'
  184. *
  185. * @return string
  186. */
  187. public function mobileNumber()
  188. {
  189. return ltrim(static::numerify($this->generator->parse(
  190. static::randomElement(static::$mobileFormats)
  191. )));
  192. }
  193. /**
  194. * @deprecated Use PhoneNumber::mobileNumber() instead.
  195. */
  196. public static function mobilePhoneNumber()
  197. {
  198. return static::numerify(
  199. strtr(static::randomElement(static::$mobileFormats), [
  200. '{{internationalCodePrefix}}' => static::internationalCodePrefix(),
  201. '{{mobileCode}}' => static::mobileCode(),
  202. ])
  203. );
  204. }
  205. /**
  206. * Generate a personal number.
  207. *
  208. * @example A personal number: '7012345678'
  209. * @example A personal number with spaces: '70 1234 5678'
  210. * @example A personal number with international code prefix: '+307012345678'
  211. * @example A personal number with international code prefix and spaces: '+30 70 1234 5678'
  212. *
  213. * @return string
  214. */
  215. public function personalNumber()
  216. {
  217. return ltrim(static::numerify($this->generator->parse(
  218. static::randomElement(static::$personalFormats)
  219. )));
  220. }
  221. /**
  222. * Generate a toll-free number.
  223. *
  224. * @example A toll-free number: '8001234567'
  225. * @example A toll-free number with spaces: '800 123 4567'
  226. * @example A toll-free number with international code prefix: '+308001234567'
  227. * @example A toll-free number with international code prefix and spaces: '+30 800 123 4567'
  228. *
  229. * @return string
  230. */
  231. public static function tollFreeNumber()
  232. {
  233. return ltrim(static::numerify(
  234. strtr(static::randomElement(static::$tollFreeFormats), [
  235. '{{internationalCodePrefix}}' => static::internationalCodePrefix(),
  236. ])
  237. ));
  238. }
  239. /**
  240. * Generate a code for a shared-cost number.
  241. *
  242. * @internal Used to generate shared-cost numbers.
  243. *
  244. * @return string
  245. */
  246. public static function sharedCostCode()
  247. {
  248. return static::randomElement(static::$sharedCostCodes);
  249. }
  250. /**
  251. * Generate a shared-cost number.
  252. *
  253. * @example A shared-cost number: '8011234567'
  254. * @example A shared-cost number with spaces: '801 123 4567'
  255. * @example A shared-cost number with international code prefix: '+308011234567'
  256. * @example A shared-cost number with international code prefix and spaces: '+30 801 123 4567'
  257. *
  258. * @return string
  259. */
  260. public function sharedCostNumber()
  261. {
  262. return ltrim(static::numerify($this->generator->parse(
  263. static::randomElement(static::$sharedCostFormats)
  264. )));
  265. }
  266. /**
  267. * Generate a code for a premium-rate number.
  268. *
  269. * @internal Used to generate premium-rate numbers.
  270. *
  271. * @return string
  272. */
  273. public static function premiumRateCode()
  274. {
  275. return static::randomElement(static::$premiumRateCodes);
  276. }
  277. /**
  278. * Generate a premium-rate number.
  279. *
  280. * @example A premium-rate number: '9011234567'
  281. * @example A premium-rate number with spaces: '901 123 4567'
  282. * @example A premium-rate number with international code prefix: '+309011234567'
  283. * @example A premium-rate number with international code prefix and spaces: '+30 901 123 4567'
  284. *
  285. * @return string
  286. */
  287. public function premiumRateNumber()
  288. {
  289. return ltrim(static::numerify($this->generator->parse(
  290. static::randomElement(static::$premiumRateFormats)
  291. )));
  292. }
  293. }