55namespace Brick \PhoneNumber ;
66
77use JsonSerializable ;
8- use Override ;
9- use Stringable ;
108use libphonenumber ;
119use libphonenumber \geocoding \PhoneNumberOfflineGeocoder ;
10+ use libphonenumber \NumberParseException ;
1211use libphonenumber \PhoneNumberToCarrierMapper ;
1312use libphonenumber \PhoneNumberToTimeZonesMapper ;
14- use libphonenumber \NumberParseException ;
1513use libphonenumber \PhoneNumberUtil ;
14+ use Override ;
15+ use Stringable ;
16+
17+ use function assert ;
18+ use function substr ;
1619
1720/**
1821 * A phone number.
@@ -38,15 +41,13 @@ private function __construct(libphonenumber\PhoneNumber $phoneNumber)
3841 * @param string $phoneNumber The phone number to parse.
3942 * @param string|null $regionCode The region code to assume, if the number is not in international format.
4043 *
41- * @return PhoneNumber
42- *
4344 * @throws PhoneNumberParseException
4445 */
45- public static function parse (string $ phoneNumber , ?string $ regionCode = null ) : PhoneNumber
46+ public static function parse (string $ phoneNumber , ?string $ regionCode = null ): PhoneNumber
4647 {
4748 try {
4849 return new PhoneNumber (
49- PhoneNumberUtil::getInstance ()->parse ($ phoneNumber , $ regionCode )
50+ PhoneNumberUtil::getInstance ()->parse ($ phoneNumber , $ regionCode ),
5051 );
5152 } catch (NumberParseException $ e ) {
5253 throw new PhoneNumberParseException ($ e );
@@ -57,11 +58,9 @@ public static function parse(string $phoneNumber, ?string $regionCode = null) :
5758 * @param string $regionCode The region code.
5859 * @param PhoneNumberType $phoneNumberType The phone number type, defaults to a fixed line.
5960 *
60- * @return PhoneNumber
61- *
6261 * @throws PhoneNumberException If no example number is available for this region and type.
6362 */
64- public static function getExampleNumber (string $ regionCode , PhoneNumberType $ phoneNumberType = PhoneNumberType::FIXED_LINE ) : PhoneNumber
63+ public static function getExampleNumber (string $ regionCode , PhoneNumberType $ phoneNumberType = PhoneNumberType::FIXED_LINE ): PhoneNumber
6564 {
6665 $ phoneNumber = PhoneNumberUtil::getInstance ()->getExampleNumberForType (
6766 $ regionCode ,
@@ -79,10 +78,8 @@ public static function getExampleNumber(string $regionCode, PhoneNumberType $pho
7978 * Returns the country code of this PhoneNumber.
8079 *
8180 * The country code is a series of 1 to 3 digits, as defined per the E.164 recommendation.
82- *
83- * @return string
8481 */
85- public function getCountryCode () : string
82+ public function getCountryCode (): string
8683 {
8784 $ countryCode = $ this ->phoneNumber ->getCountryCode ();
8885 assert ($ countryCode !== null );
@@ -101,10 +98,8 @@ public function getCountryCode() : string
10198 * - some geographical numbers have no area codes.
10299 *
103100 * If this number has no area code, an empty string is returned.
104- *
105- * @return string
106101 */
107- public function getGeographicalAreaCode () : string
102+ public function getGeographicalAreaCode (): string
108103 {
109104 $ phoneNumberUtil = PhoneNumberUtil::getInstance ();
110105
@@ -119,10 +114,8 @@ public function getGeographicalAreaCode() : string
119114 * Returns the national number of this PhoneNumber.
120115 *
121116 * The national number is a series of digits.
122- *
123- * @return string
124117 */
125- public function getNationalNumber () : string
118+ public function getNationalNumber (): string
126119 {
127120 $ nationalNumber = $ this ->phoneNumber ->getNationalNumber ();
128121 assert ($ nationalNumber !== null );
@@ -140,7 +133,7 @@ public function getNationalNumber() : string
140133 *
141134 * @return string|null The region code, or null if the number does not map to a geographic region.
142135 */
143- public function getRegionCode () : ?string
136+ public function getRegionCode (): ?string
144137 {
145138 $ regionCode = PhoneNumberUtil::getInstance ()->getRegionCodeForNumber ($ this ->phoneNumber );
146139
@@ -155,10 +148,8 @@ public function getRegionCode() : ?string
155148 * Returns whether this phone number is a possible number.
156149 *
157150 * Note this provides a more lenient and faster check than `isValidNumber()`.
158- *
159- * @return bool
160151 */
161- public function isPossibleNumber () : bool
152+ public function isPossibleNumber (): bool
162153 {
163154 return PhoneNumberUtil::getInstance ()->isPossibleNumber ($ this ->phoneNumber );
164155 }
@@ -168,18 +159,16 @@ public function isPossibleNumber() : bool
168159 *
169160 * Note this doesn't verify the number is actually in use,
170161 * which is impossible to tell by just looking at a number itself.
171- *
172- * @return bool
173162 */
174- public function isValidNumber () : bool
163+ public function isValidNumber (): bool
175164 {
176165 return PhoneNumberUtil::getInstance ()->isValidNumber ($ this ->phoneNumber );
177166 }
178167
179168 /**
180169 * Returns the type of this phone number.
181170 */
182- public function getNumberType () : PhoneNumberType
171+ public function getNumberType (): PhoneNumberType
183172 {
184173 return PhoneNumberType::from (
185174 PhoneNumberUtil::getInstance ()->getNumberType ($ this ->phoneNumber )->value ,
@@ -189,7 +178,7 @@ public function getNumberType() : PhoneNumberType
189178 /**
190179 * Returns a formatted string representation of this phone number.
191180 */
192- public function format (PhoneNumberFormat $ format ) : string
181+ public function format (PhoneNumberFormat $ format ): string
193182 {
194183 return PhoneNumberUtil::getInstance ()->format (
195184 $ this ->phoneNumber ,
@@ -200,11 +189,9 @@ public function format(PhoneNumberFormat $format) : string
200189 /**
201190 * Formats this phone number for out-of-country dialing purposes.
202191 *
203- * @param string $regionCode The ISO 3166-1 alpha-2 country code
204- *
205- * @return string
192+ * @param string $regionCode The ISO 3166-1 alpha-2 country code.
206193 */
207- public function formatForCallingFrom (string $ regionCode ) : string
194+ public function formatForCallingFrom (string $ regionCode ): string
208195 {
209196 return PhoneNumberUtil::getInstance ()->formatOutOfCountryCallingNumber ($ this ->phoneNumber , $ regionCode );
210197 }
@@ -259,15 +246,13 @@ public function jsonSerialize(): string
259246 * @param string|null $userRegion The region code for a given user. This region will be omitted from the description
260247 * if the phone number comes from this region. It is a two-letter uppercase CLDR
261248 * region code.
262- *
263- * @return string|null
264249 */
265- public function getDescription (string $ locale , ?string $ userRegion = null ) : ?string
250+ public function getDescription (string $ locale , ?string $ userRegion = null ): ?string
266251 {
267252 $ description = PhoneNumberOfflineGeocoder::getInstance ()->getDescriptionForNumber (
268253 $ this ->phoneNumber ,
269254 $ locale ,
270- $ userRegion
255+ $ userRegion,
271256 );
272257
273258 if ($ description === '' ) {
@@ -327,11 +312,9 @@ public function getTimeZones(): array
327312
328313 /**
329314 * Returns a string representation of this phone number in international E164 format.
330- *
331- * @return string
332315 */
333316 #[Override]
334- public function __toString () : string
317+ public function __toString (): string
335318 {
336319 return $ this ->format (PhoneNumberFormat::E164 );
337320 }
0 commit comments