Skip to content

Commit

Permalink
Fixes #925
Browse files Browse the repository at this point in the history
- Override $e164Formats in order to provide locale specific phone
  numbers (mobile and landline) in E.164 format.

- Add constants / static properties for common formatting codes (country,
  area and mobile service).

- Add methods 'e164MobileNumber' and 'e164LandlineNumber' to provide
  mobile-only and landline-only phone numbers, respectively.
  • Loading branch information
Head0nF1re committed Dec 13, 2024
1 parent 2114cc6 commit 2570540
Showing 1 changed file with 113 additions and 26 deletions.
139 changes: 113 additions & 26 deletions src/Provider/pt_PT/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,74 @@

class PhoneNumber extends \Faker\Provider\PhoneNumber
{
/**
* Returns the pt_PT phone country code.
*/
const COUNTRY_CODE = '+351';

/**
* pt_PT Mobile Service Codes
*/
protected static $mobileServiceCode = [
91,
92,
93,
96,
];

/**
* pt_PT Geographic Area Codes
*/
protected static $areaCode = [
21,
22,
23,
24,
25,
26,
27,
28,
29,
];

/**
* pt_PT Geographic Area and Mobile Service Codes
*/
protected static $areaOrMobileServiceCode = [
91,
92,
93,
96,
21,
22,
23,
24,
25,
26,
27,
28,
29,
];

/**
* @see http://en.wikipedia.org/wiki/Telephone_numbers_in_Portugal
*/
protected static $formats = [
'+351 91#######',
'+351 92#######',
'+351 93#######',
'+351 96#######',
'+351 21#######',
'+351 22#######',
'+351 23#######',
'+351 24#######',
'+351 25#######',
'+351 26#######',
'+351 27#######',
'+351 28#######',
'+351 29#######',
'91#######',
'92#######',
'93#######',
'96#######',
'21#######',
'22#######',
'23#######',
'24#######',
'25#######',
'26#######',
'27#######',
'28#######',
'29#######',
'{{countryCode}} {{areaOrMobileServiceCode}}#######',
'{{mobileServiceCode}}#######',
'{{areaCode}}#######',
];

protected static $e164Formats = [
'{{countryCode}}{{areaOrMobileServiceCode}}#######',
];

protected static $e164MobileFormat = [
'{{countryCode}}{{mobileServiceCode}}#######',
];

protected static $e164LandlineFormat = [
'{{countryCode}}{{areaCode}}#######',
];

protected static $mobileNumberPrefixes = [
Expand All @@ -47,4 +85,53 @@ public static function mobileNumber()
{
return static::numerify(static::randomElement(static::$mobileNumberPrefixes));
}

public static function areaOrMobileServiceCode()
{
return self::randomElement(static::$areaOrMobileServiceCode);
}

public static function areaCode()
{
return self::randomElement(static::$areaCode);
}

public static function mobileServiceCode()
{
return self::randomElement(static::$mobileServiceCode);
}

/**
* Returns the pt_PT phone country code.
*
* @return string
*/
public static function countryCode()
{
return self::COUNTRY_CODE;
}

/**
* Returns a pt_PT mobile number in E.164 format.
*
* Example: +35193XXXXXXX
*
* @return string
*/
public function e164MobileNumber()
{
return static::numerify($this->generator->parse(static::randomElement(static::$e164MobileFormat)));
}

/**
* Returns a pt_PT landline number in E.164 format.
*
* Example: +35121XXXXXXX
*
* @return string
*/
public function e164LandlineNumber()
{
return static::numerify($this->generator->parse(static::randomElement(static::$e164LandlineFormat)));
}
}

0 comments on commit 2570540

Please sign in to comment.