Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseHelper() method of PhoneNumber class didn't implement #213

Closed
steepbeaver opened this issue Jan 17, 2023 · 3 comments
Closed

parseHelper() method of PhoneNumber class didn't implement #213

steepbeaver opened this issue Jan 17, 2023 · 3 comments

Comments

@steepbeaver
Copy link

steepbeaver commented Jan 17, 2023

When I try to work with this Laravel interface of libphonenumber package all the time I need to specify $country as a param of the make static method.

$phoneNumber =  PhoneNumber::make('US+1 XXXXXXXXXX', 'US')->formatInternational();

If I try to do it without a country code I get the error.

Result: Error type: 0. Number requires a country to be specified.
$phoneNumber = PhoneNumber::make('US+1 XXXXXXXXXX')->formatInternational();

But when I use libphonenumber package directly I can do like this:

$phoneNumberUtilInstance = PhoneNumberUtil::getInstance();
$phoneNumberInstance = $phoneNumberUtilInstance->parse($phoneNumber);

// Result: +1 XXXXXXXXXX
$phoneNumber =  $phoneNumberUtilInstance->format('US+1 XXXXXXXXXX', PhoneNumberFormat::INTERNATIONAL);

1

@Propaganistas
Copy link
Owner

Propaganistas commented Jan 18, 2023

This test demonstrates the behavior you want.

public function it_can_format_international_numbers_without_given_country()
{
$object = new PhoneNumber('+3212345678');
$this->assertEquals('012 34 56 78', $object->format(PhoneNumberFormat::NATIONAL));
}

I'm not sure why you're adding "US" in front of the number though.

Feel free to investigate and create a PR with tests.

@steepbeaver
Copy link
Author

@Propaganistas I guess you didn't understand my question. It was about this line:

$phoneNumber =  $phoneNumberUtilInstance->format('US+1 XXXXXXXXXX', PhoneNumberFormat::INTERNATIONAL);

which is supported by libphonenumber\PhoneNumberUtil.

When I try to use your example:

$object = new PhoneNumber('US+1 2123456781'); 
$this->assertEquals('012 34 56 78', $object->format(PhoneNumberFormat::NATIONAL)); 

I get Number requires a country to be specified. error

Propaganistas added a commit that referenced this issue Jan 27, 2023
@Propaganistas
Copy link
Owner

fixed and new release tagged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants