Skip to content

Commit

Permalink
getCountryCode()
Browse files Browse the repository at this point in the history
  • Loading branch information
shimonewman committed May 8, 2024
1 parent 9ff260b commit 6d64086
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 45 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"ext-curl": "*",
"ext-openssl": "*",
"phpmailer/phpmailer": "6.9.1",
"giggsey/libphonenumber-for-php-lite": "8.13.30"

"giggsey/libphonenumber-for-php-lite": "8.13.36"
},
"require-dev": {
"phpunit/phpunit": "10.5.10",
Expand Down
37 changes: 19 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/Utopia/Messaging/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Utopia\Messaging;

use Exception;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberUtil;

abstract class Adapter
Expand Down Expand Up @@ -272,8 +271,8 @@ public function getCountryCode(string $phone): ?int
->parse($phone)
->getCountryCode();

} catch (NumberParseException $e) {
throw new Exception("Error parsing phone: " . $e->getMessage());
} catch (\Throwable $th) {
throw new Exception("Error parsing phone: " . $th->getMessage());
}
}
}
22 changes: 0 additions & 22 deletions src/Utopia/Messaging/Adapter/SMS/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,4 @@ protected function process(SMSMessage $message): array
return $response->toArray();
}

/**
* @param string $phone
* @return int|null
* @throws Exception
*/
public function getCountryCode(string $phone): ?int
{
if (empty($phone)) {
throw new \Exception('No phone number was passed.');
}

$helper = PhoneNumberUtil::getInstance();

try {
return $helper
->parse($phone)
->getCountryCode();

} catch (NumberParseException $e) {
throw new \Exception("Error parsing phone: " . $e->getMessage());
}
}
}

0 comments on commit 6d64086

Please sign in to comment.