cherif / algerian-mobile-phone-number
Algerian mobile phone number value object
Requires
- php: >=7.2.0
Requires (Dev)
- phpspec/phpspec: ^6.1
README
Algerian mobile phone number value object implementation that can be used in your domain models or to integrate with your favorite framework.
Installation
composer require cherif/algerian-mobile-phone-number
Usage:
Instantiation:
The class doesn't have a public constructor, it has a named constructor instead in order to preseve its invariants:
use Cherif\AlgerianMobilePhoneNumber\AlgerianMobilePhoneNumber; $phoneNumber = AlgerianMobilePhoneNumber::fromString('0699000000');
Or:
use Cherif\AlgerianMobilePhoneNumber\AlgerianMobilePhoneNumber; $phoneNumber = AlgerianMobilePhoneNumber::fromString('06 99 00 00 00');
Or:
use Cherif\AlgerianMobilePhoneNumber\AlgerianMobilePhoneNumber; $phoneNumber = AlgerianMobilePhoneNumber::fromString('06-99-00-00-00'); //
The value object class accepts international phone indicative, 00213 or +213, too.
NOTE: For now only space and dash "-" separated numbers are accepted.
API:
asString
To get the string value of the object:
$phoneNumber->asString(); // -> '0699000000'
equals
For comparaison check:
$other = AlgerianMobilePhoneNumber::fromString('0699000000'); $phoneNumber->equals($other); // -> true
isMobilis, isDjezzy and isOoredoo
To know if the object respresents a Mobilis, Djezzy or Ooredoo phone number
$phoneNumber = AlgerianMobilePhoneNumber::fromString('0699000000'); $phoneNumber->isMobilis(); // -> true $phoneNumber->isDjezzy(); // -> false $phoneNumber->isOoredoo(); // -> false
withNumber
use Cherif\AlgerianMobilePhoneNumber\AlgerianMobilePhoneNumber; $phoneNumber = AlgerianMobilePhoneNumber::fromString('06-99-00-00-00'); $phoneNumber->withNumber('07-99-00-00-00'); // Will return a new instance that represents the new number
__toString
Casts the value object to string:
$phoneNumber = AlgerianMobilePhoneNumber::fromString('0699000000'); (string)$phoneNumber; // -> '0699000000'
Contribution
Contributions are welcome to make this library better.
- Clone the repo:
$ git clone git@github.com:cherifGsoul/php-algerian-mobile-phone-number.git
and enter to the cloned repository directory.
- Install dependencies:
$ composer install
Testing:
Run composer script for testing:
$ composer test