Permalink
Browse files

Added testParseNationalNumber test

  • Loading branch information...
1 parent d602d25 commit 61d5596bd4e063676f6abcdc15e3580c3bffcb68 @davideme committed Apr 8, 2012
Showing with 681 additions and 20 deletions.
  1. +46 −0 NumberParseException.php
  2. +19 −11 PhoneNumber.php
  3. +571 −9 PhoneNumberUtil.php
  4. +45 −0 Tests/PhoneNumberUtilTest.php
View
@@ -0,0 +1,46 @@
+<?php
+
+namespace com\google\i18n\phonenumbers;
+
+/**
+ * Generic exception class for errors encountered when parsing phone numbers.
+ * @author Lara Rennie
+ */
+class NumberParseException extends \Exception {
+
+ const INVALID_COUNTRY_CODE = 0;
+ // This generally indicates the string passed in had less than 3 digits in it. More
+ // specifically, the number failed to match the regular expression VALID_PHONE_NUMBER in
+ // PhoneNumberUtil.java.
+ const NOT_A_NUMBER = 1;
+ // This indicates the string started with an international dialing prefix, but after this was
+ // stripped from the number, had less digits than any valid phone number (including country
+ // code) could have.
+ const TOO_SHORT_AFTER_IDD = 2;
+ // This indicates the string, after any country code has been stripped, had less digits than any
+ // valid phone number could have.
+ const TOO_SHORT_NSN = 3;
+ // This indicates the string had more digits than any valid phone number could have.
+ const TOO_LONG = 4;
+
+ private $errorType;
+ protected $message;
+
+ public function __construct($errorType, $message) {
+ parent::__construct($message, $errorType);
+ $this->message = $message;
+ $this->errorType = $errorType;
+ }
+
+ /**
+ * Returns the error type of the exception that has been thrown.
+ */
+ public function getErrorType() {
+ return $this->errorType;
+ }
+
+ public function __toString() {
+ return "Error type: " . $this->errorType . ". " . $this->message;
+ }
+
+}
View
@@ -112,15 +112,23 @@ public function clearRawInput() {
$this->rawInput = NULL;
return $this;
}
-
- public function clear() {
- $this->clearCountryCode();
- $this->clearNationalNumber();
- $this->clearExtension();
- $this->clearItalianLeadingZero();
- $this->clearRawInput();
-/* $this->clearCountryCodeSource();
- $this->clearPreferredDomesticCarrierCode();
- */ return $this;
- }
+
+ public function clear() {
+ $this->clearCountryCode();
+ $this->clearNationalNumber();
+ $this->clearExtension();
+ $this->clearItalianLeadingZero();
+ $this->clearRawInput();
+ /* $this->clearCountryCodeSource();
+ $this->clearPreferredDomesticCarrierCode();
+ */ return $this;
+ }
}
+class CountryCodeSource {
+
+ const FROM_NUMBER_WITH_PLUS_SIGN = 0;
+ const FROM_NUMBER_WITH_IDD = 1;
+ const FROM_NUMBER_WITHOUT_PLUS_SIGN = 2;
+ const FROM_DEFAULT_COUNTRY = 3;
+
+}
Oops, something went wrong.

0 comments on commit 61d5596

Please sign in to comment.