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

feat: standardise phone number format while importing vCard #1281

Merged
merged 11 commits into from
Oct 27, 2018
Merged

feat: standardise phone number format while importing vCard #1281

merged 11 commits into from
Oct 27, 2018

Conversation

Dagolin
Copy link

@Dagolin Dagolin commented May 5, 2018

Fixes #981

Enhaced by https://github.com/giggsey/libphonenumber-for-php, while importing vCard check and format the phone number as international phone number format eg +44 117 496 0123 if the country of the contact can be recognized, the format of the number is open for discussion.

Since we need the country to tell which format the number should be, I left the phone number input field of contact (On CONTACT INFORMATION area) untouched because we have no country field for phone number, and it's awkward to add it.

image

Copy link
Member

@djaiss djaiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your effort. I've added a huge comment to refactor your code - I hope it's not too harsh. Thanks in advance for your help!

@@ -526,10 +526,31 @@ public function importEmail(\App\Contact $contact): void
public function importTel(\App\Contact $contact): void
{
if (! is_null($this->formatValue($this->currentEntry->TEL))) {
$tel = (string) $this->currentEntry->TEL;

if (! is_null($this->formatValue($this->currentEntry->ADR))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This whole new section should be split, otherwise it'll be very hard to unit test this method, considering the number of if involved.
  • Ideally we should not have more than one if - here we have 3 nested ifs which is not good

You need to refactor this:

  • create a new method in an helper (in LocaleHelper for instance), something like getCountryForVCard or something, that will return the country ISO based on the vcard you pass as parameter
  • then create a new method in an helper (in LocaleHelper for instance), called formatTelephoneNumber or something, that will take both the tel number and the iso country and returns the formatted phone number (or null).
  • Then, the entire new code becomes (pseudo code and might contain errors):
$tel = $this->currentEntry->TEL;

if (! is_null($this->formatValue($tel)) {
    $tel = (string) $tel;

    $isoCode = LocaleHelper::getCountryForVCard($this->currentEntry);

    $tel = LocaleHelper::formatTelephoneNumber($tel, $isoCode);

   // and that's it, you have your phone number 
}

Then, write the unit tests for the new methods inside the Helpers, and that's it.

The idea is that a method should ideally do just one thing, not multiple things as you've done, and it will be way easier to check if something is wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djaiss Thanks for the reminding, no prob!

Copy link
Author

@Dagolin Dagolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@djaiss Thank you for all the pro detail tips and the great pseudo code, that's something I should be ready and have it done before I submit a PR, a lesson learned indeed.

I hope this did not bother you too much, thanks alot.

@djaiss
Copy link
Member

djaiss commented May 9, 2018

Thanks a lot! It never bothers me when someone take his precious personal time to help on the project 😀

I'm going to review the PR very soon, thanks!

@djaiss djaiss assigned djaiss and unassigned Dagolin May 13, 2018
Copy link

@sonarcloud sonarcloud bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonarQube analysis found issues:
Bug Bugs: 0
Vulnerability Vulnerabilities: 0
Code Smell Code Smells: 1

See all issues in SonarCloud

Copy link

@sonarcloud sonarcloud bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonarQube analysis found issues:
Bug Bugs: 0
Vulnerability Vulnerabilities: 0
Code Smell Code Smells: 1

See all issues in SonarCloud

@djaiss djaiss changed the title standardise phonenumber format while importing vCard feat: standardise phone number format while importing vCard Oct 27, 2018
@djaiss
Copy link
Member

djaiss commented Oct 27, 2018

Thanks again for your help @Dagolin

After 6 months (sigh), we've finally merged this PR.

Really sorry for the time it took to make it happen.

@djaiss djaiss merged commit de6f705 into monicahq:master Oct 27, 2018
@github-actions
Copy link

This pull request has been automatically locked since there
has not been any recent activity after it was closed.
Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Standardise phonenumber format
2 participants