From 80060ac81713474516e1566aa5907b04e0359289 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Wed, 4 Oct 2017 17:33:08 +0200 Subject: [PATCH] Scalar type hints and return types --- src/PhoneNumber.php | 20 ++++++++++---------- src/PhoneNumberParseException.php | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/PhoneNumber.php b/src/PhoneNumber.php index 728bc84..ea2f7a2 100644 --- a/src/PhoneNumber.php +++ b/src/PhoneNumber.php @@ -37,7 +37,7 @@ private function __construct(\libphonenumber\PhoneNumber $phoneNumber) * * @throws PhoneNumberParseException */ - public static function parse($phoneNumber, $regionCode = null) + public static function parse(string $phoneNumber, string $regionCode = null) : PhoneNumber { try { return new PhoneNumber( @@ -56,7 +56,7 @@ public static function parse($phoneNumber, $regionCode = null) * * @throws PhoneNumberException If no example number is available for this region and type. */ - public static function getExampleNumber($regionCode, $phoneNumberType = PhoneNumberType::FIXED_LINE) + public static function getExampleNumber(string $regionCode, int $phoneNumberType = PhoneNumberType::FIXED_LINE) : PhoneNumber { $phoneNumber = PhoneNumberUtil::getInstance()->getExampleNumberForType($regionCode, $phoneNumberType); @@ -74,7 +74,7 @@ public static function getExampleNumber($regionCode, $phoneNumberType = PhoneNum * * @return string */ - public function getCountryCode() + public function getCountryCode() : string { return (string) $this->phoneNumber->getCountryCode(); } @@ -86,7 +86,7 @@ public function getCountryCode() * * @return string */ - public function getNationalNumber() + public function getNationalNumber() : string { return $this->phoneNumber->getNationalNumber(); } @@ -101,7 +101,7 @@ public function getNationalNumber() * * @return string|null The region code, or null if the number does not map to a geographic region. */ - public function getRegionCode() + public function getRegionCode() : ?string { $regionCode = PhoneNumberUtil::getInstance()->getRegionCodeForNumber($this->phoneNumber); @@ -120,7 +120,7 @@ public function getRegionCode() * * @return bool */ - public function isValidNumber() + public function isValidNumber() : bool { return PhoneNumberUtil::getInstance()->isValidNumber($this->phoneNumber); } @@ -130,7 +130,7 @@ public function isValidNumber() * * @return int One of the PhoneNumberType constants. */ - public function getNumberType() + public function getNumberType() : int { return PhoneNumberUtil::getInstance()->getNumberType($this->phoneNumber); } @@ -142,7 +142,7 @@ public function getNumberType() * * @return string */ - public function format($format) + public function format(int $format) : string { return PhoneNumberUtil::getInstance()->format($this->phoneNumber, $format); } @@ -154,7 +154,7 @@ public function format($format) * * @return string */ - public function formatForCallingFrom($regionCode) + public function formatForCallingFrom(string $regionCode) : string { return PhoneNumberUtil::getInstance()->formatOutOfCountryCallingNumber($this->phoneNumber, $regionCode); } @@ -164,7 +164,7 @@ public function formatForCallingFrom($regionCode) * * @return string */ - public function __toString() + public function __toString() : string { return $this->format(PhoneNumberFormat::E164); } diff --git a/src/PhoneNumberParseException.php b/src/PhoneNumberParseException.php index 580768e..5b25b2e 100644 --- a/src/PhoneNumberParseException.php +++ b/src/PhoneNumberParseException.php @@ -14,7 +14,7 @@ class PhoneNumberParseException extends PhoneNumberException * * @return PhoneNumberParseException */ - public static function wrap(\Exception $e) + public static function wrap(\Exception $e) : PhoneNumberParseException { return new PhoneNumberParseException($e->getMessage(), $e->getCode(), $e); }