Download the PHP package safeaccess/identum without Composer
On this page you can find all versions of the php package safeaccess/identum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download safeaccess/identum
More information about safeaccess/identum
Files in safeaccess/identum
Package identum
Short Description Brazilian document validation library (CPF, CNPJ, CEP, CNH, CNS, PIS, IE, RENAVAM, Voter Title, Mercosul Plate)
License MIT
Homepage https://github.com/felipesauer/safeaccess-identum
Informations about the package identum
Safe Access Identum — PHP
PHP library for validating Brazilian documents — CPF, CNPJ, CNH, CEP, CNS, PIS, IE (all 27 states), RENAVAM, Mercosul Plate, Voter Title, Payment Card, PIX key, and Certificate. Input sanitization by default. Zero production dependencies.
Version 2.0.
validate()now returns a rich result object instead of a boolean, with new capabilities (format,generate, metadata) and document types. Upgrading from 1.x? See Migrating from 1.x.
Features
- 13 document types — CPF, CNPJ (alphanumeric), CNH, CEP, CNS, PIS, IE (all 27 states), RENAVAM, Mercosul Plate, Voter Title, plus Payment Card (Luhn), PIX key, and civil-registry Certificate
- Rich result —
validate()returns{ valid, reason, normalized, meta };isValid()is the boolean shortcut - Machine-readable reasons — every failure carries a stable
ReasonCode(invalid_format,wrong_length,bad_check_digit,unknown_uf,known_invalid,denied) - Metadata extraction — offline, from the number: CPF/IE
uf, CNStype, CNPJisMatriz/isAlphanumeric, Cardbrand, PIXkeyType, Certificatetype format()/strip()— apply or remove the canonical maskgenerate()— valid documents for tests (Identum::generateCpf(), …)- IE all 27 states — every state algorithm implemented and tested with edge cases
- Input sanitization by default —
'529.982.247-25'and'52998224725'both just work - Allow list / deny list — force-accept or force-reject specific values (allow list wins)
- 100% line coverage — tested with Pest 3 · Infection mutation testing (≥ 85% MSI)
- Zero production dependencies — pure PHP 8.2+
The problem
Validating Brazilian documents in PHP accumulates silently: scattered regexes, copy-pasted Mod-11 loops, and 27 state-specific IE algorithms scattered across the codebase. Each re-implementation gets Bahia's dual-modulus branch wrong and ships with no edge-case tests.
Without this library:
With this library:
Installation
Requirements: PHP 8.2+
Quick start
Direct instantiation
API
All validator classes share the same fluent interface after construction:
| Method | Return | Description |
|---|---|---|
validate() |
ValidationResult |
Rich result: { valid, reason, normalized, meta } |
isValid() |
bool |
Boolean shortcut for validate()->valid |
validateOrFail() |
void |
Throws ValidationException (with document, reason, normalized) when invalid |
format() |
string |
Canonical mask applied, best-effort |
strip() |
string |
Canonical value with mask characters removed |
denyList(string[]) |
static |
Force-reject the specified values regardless of checksum |
allowList(string[]) |
static |
Force-accept the specified values regardless of checksum |
raw() |
string |
The input exactly as provided |
blacklist()/whitelist()still work as deprecated aliases ofdenyList()/allowList()and will be removed in 3.0.
Reason codes (stable, snake_case), in the order they are checked: invalid_format → wrong_length → bad_check_digit → unknown_uf → known_invalid → denied.
Generators — one per type on the facade: generateCpf(), generateCnpj(), generateCnh(), generateCep(), generateCns(), generatePis(), generateIe($state), generateRenavam(), generatePlaca(), generateTituloEleitor(). Unmasked by default; pass formatted: true where a mask exists.
Supported documents
| Document | Alias | Class |
|---|---|---|
| CPF | cpf |
CPFValidation |
| CNPJ | cnpj |
CNPJValidation |
| CNH | cnh |
CNHValidation |
| CEP | cep |
CEPValidation |
| CNS | cns |
CNSValidation |
| PIS/PASEP | pis |
PISValidation |
| IE | ie |
IEValidation |
| RENAVAM | renavam |
RenavamValidation |
| Mercosul Plate | placa |
PlateMercosulValidation |
| Voter Title | tituloEleitor |
VoterTitleValidation |
| Payment Card | cartao |
CartaoValidation |
| PIX key | pix |
PixValidation |
| Certificate | certidao |
CertidaoValidation |
IE — all 27 states
CNPJ — alfanumérico
Payment Card, PIX and Certificate
Card validation is Luhn integrity plus best-effort brand — it does not prove a card exists (that needs an online lookup). PIX validates key format (and CPF/CNPJ checksums), not DICT registration. Both are offline by design.
Contributing
See CONTRIBUTING.md for development setup, commit conventions, and pull request guidelines.
License
MIT © Felipe Sauer