Brick PhoneNumber

Parse, validate, and format phone numbers as immutable PHP value objects.

Library
Composer
v0.8.0
426stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
41/100Fair
Development Activity8
Maintenance20
Community56
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture82
Code Quality84
Innovation62
Learning Curve88

Brick PhoneNumber is a PHP library that provides a clean, immutable PhoneNumber value object on top of Google’s libphonenumber (via giggsey/libphonenumber-for-php). It parses raw phone number strings into strongly-typed objects, validates them against real numbering plans, and formats them in E.164, international, national, and RFC3966 styles.

By wrapping the powerful but low-level libphonenumber in a small, focused API, it gives applications a dependable way to store, compare, and display phone numbers. The value object exposes the number’s region, type (mobile, fixed line, toll-free, and more), and validity, and throws typed exceptions with detailed parse-error information when input cannot be interpreted.

What You Get

  • An immutable PhoneNumber value object with a small, focused API
  • Parsing of raw numbers with region hints and typed parse errors
  • Validation against real numbering plans via libphonenumber
  • Formatting in E.164, international, national, and RFC3966 styles
  • Number metadata: region code, number type, and possible/valid checks

Common Use Cases

  • Validating user-entered phone numbers during signup or checkout
  • Normalizing numbers to E.164 before storing them in a database
  • Formatting stored numbers for display in a user’s local style
  • Detecting whether a number is mobile, fixed line, or toll-free

Under The Hood

Architecture - The library is a thin, well-typed facade over libphonenumber. The core src/PhoneNumber.php holds an underlying libphonenumber object and delegates parsing, validation, and formatting to it while exposing an immutable, ergonomic surface. Supporting enums and value types (PhoneNumberFormat, PhoneNumberType, CarrierNameMode, PhoneNumberParseErrorType) replace libphonenumber’s integer constants with typed PHP enums, and PhoneNumberParseException carries a structured error type when parsing fails.

Tech Stack - PHP 8.1+, depending solely on giggsey/libphonenumber-for-php (^9.0), the PHP port of Google’s libphonenumber. Development uses PHPUnit and PHPStan (2.1.x) for testing and static analysis.

Code Quality - The source is small (a handful of classes and enums), strongly typed, and covered by a tests/ suite plus PHPStan analysis. Immutability and typed exceptions make the API hard to misuse. Development activity is low, but that reflects a stable, mature wrapper over an actively-maintained dependency.

API Design - The public API is deliberately minimal and discoverable: static factory methods (parse) return a PhoneNumber, and instance methods expose formatting, region, type, and validity. Using PHP enums for formats and types makes calls self-documenting and IDE-friendly, and getting a validated, formatted number takes only a line or two.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search