Skip to content
This repository was archived by the owner on Mar 29, 2020. It is now read-only.
This repository was archived by the owner on Mar 29, 2020. It is now read-only.

Sanity checking phone number via Beberlei\Assertion::e164() worth it? #9

Description

@Revisor

The ApiSmsManager checks whether recipients' phone numbers follow the E.164 recommendation (lines 98 - 102):

foreach ($smsMessage->getRecipients() as $recipient) {
    Assertion::e164($recipient);
    $numberList->addChild('Number', $recipient);
    $hasAnyNumber = true;
}

It does this by pulling the whole Beberlei/Assert library and calling the method \Assert\Assertion::e164(), which by itself is nothing more than a small regex:

if (!\preg_match('/^\+?[1-9]\d{1,14}$/', $value))

My questions:

  1. Is it worth it pulling down a whole library just for one regex? Maybe it would be better to drop the dependency and just check this manually, with your own method.
  2. The E.164 is just a recommendation and it doesn't get followed. See Falsehood about phone numbers nr. 15:

ITU-T specifies that a phone number cannot be longer than fifteen digits, with one to three digits reserved for the country calling code, but valid numbers in Germany have been assigned that are longer than this.

Maybe this library could drop the Assertion dependency and just loosely sanity-check whether the given number looks like a phone number, something like

if ( ! preg_match('/^\+?\d+$/', $phoneNumber))

Checking if the number is a real phone number (let alone one which can receive SMS) is much more complicated and there is a whole huge library for it, so I would leave it out.

What do you think?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions