PHPackages                             safeaccess/identum - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. safeaccess/identum

ActiveLibrary[Testing &amp; Quality](/categories/testing)

safeaccess/identum
==================

Brazilian document validation library (CPF, CNPJ, CEP, CNH, CNS, PIS, IE, RENAVAM, Voter Title, Mercosul Plate)

0.1.7(1mo ago)07MITPHPPHP ^8.2

Since Apr 14Pushed 1mo agoCompare

[ Source](https://github.com/felipesauer/safeaccess-identum-php)[ Packagist](https://packagist.org/packages/safeaccess/identum)[ Docs](https://github.com/felipesauer/safeaccess-identum)[ GitHub Sponsors](https://github.com/sponsors/felipesauer)[ RSS](/packages/safeaccess-identum/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (8)Versions (9)Used By (0)

 [![safeaccess-identum logo](https://raw.githubusercontent.com/felipesauer/safeaccess-identum/main/.github/assets/logo.svg)](https://raw.githubusercontent.com/felipesauer/safeaccess-identum/main/.github/assets/logo.svg)

Safe Access Identum — PHP
=========================

[](#safe-access-identum--php)

PHP library for validating Brazilian documents — CPF, CNPJ, CNH, CEP, CNS, PIS, IE (all 27 states), RENAVAM, Mercosul Plate, and Voter Title. Input sanitization by default. Zero production dependencies.

 [![Packagist](https://camo.githubusercontent.com/e2d77c55c8676fdee8534e3b97958ceaeff9d7f276782ea68d8e12d3d8cd65c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736166656163636573732f6964656e74756d3f6c6162656c3d7061636b6167697374)](https://packagist.org/packages/safeaccess/identum) [![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](../../LICENSE) [![PHP 8.2+](https://camo.githubusercontent.com/ccaa43fc634d348cffccb1d8db7b55d9f17c5d46944bc99a15c3c982724b387d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/ccaa43fc634d348cffccb1d8db7b55d9f17c5d46944bc99a15c3c982724b387d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465) [![PHPStan max](https://camo.githubusercontent.com/f2568d8beea68c8a86467f6ba935b0c4d58f5e9658a938509f7cd62d2793b582/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6d61782d304136444144)](https://camo.githubusercontent.com/f2568d8beea68c8a86467f6ba935b0c4d58f5e9658a938509f7cd62d2793b582/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6d61782d304136444144) [![Tested with Pest](https://camo.githubusercontent.com/2656eb78211bc4cfda004686e4bdcea8c19c9bef4c374f55531694d9d21b28b3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f546573746564253230776974682d506573742d464635373333)](https://camo.githubusercontent.com/2656eb78211bc4cfda004686e4bdcea8c19c9bef4c374f55531694d9d21b28b3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f546573746564253230776974682d506573742d464635373333) [![Infection MSI](https://camo.githubusercontent.com/a7675cba29953f37883f03f52d76d8224e4bca59ddc7093938ec7799850c11df/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f676973742e67697468756275736572636f6e74656e742e636f6d2f66656c69706573617565722f38306336303262313731303766383866623137373934643464343463393466612f7261772f696e66656374696f6e2d6d73692e6a736f6e)](https://camo.githubusercontent.com/a7675cba29953f37883f03f52d76d8224e4bca59ddc7093938ec7799850c11df/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f676973742e67697468756275736572636f6e74656e742e636f6d2f66656c69706573617565722f38306336303262313731303766383866623137373934643464343463393466612f7261772f696e66656374696f6e2d6d73692e6a736f6e)

---

Features
--------

[](#features)

- **10 document types** — CPF, CNPJ (alphanumeric), CNH, CEP, CNS, PIS, IE (all 27 states), RENAVAM, Mercosul Plate, Voter Title
- **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
- **`validateOrFail()`** — throws `ValidationException` instead of returning `false`
- **Blacklist / whitelist** — force-accept or force-reject specific values
- **100% line + branch coverage** — tested with Pest 3 · Infection mutation testing (≥ 85% MSI)
- **Zero production dependencies** — pure PHP 8.2+

The problem
-----------

[](#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:**

```
function validateCpf(string $cpf): bool {
    $cpf = preg_replace('/\D/', '', $cpf);
    if (strlen($cpf) !== 11 || preg_match('/(\d)\1{10}/', $cpf)) return false;
    // 30+ lines: loops, hardcoded weights, manual digit comparison...
}
```

**With this library:**

```
Identum::cpf('529.982.247-25')->validate();                    // true
Identum::ie('343.173.196.450', StateEnum::SP)->validate();     // true — all 27 states
```

Installation
------------

[](#installation)

```
composer require safeaccess/identum
```

**Requirements:** PHP 8.2+

Quick start
-----------

[](#quick-start)

```
use SafeAccess\Identum\Identum;
use SafeAccess\Identum\Assets\IE\StateEnum;
use SafeAccess\Identum\Exceptions\ValidationException;

// All document types — formatting stripped automatically
Identum::cpf('529.982.247-25')->validate();                      // true
Identum::cnpj('84.773.274/0001-03')->validate();                 // true
Identum::cnpj('A0000000000032')->validate();                     // true — alphanumeric CNPJ
Identum::cnh('22522791508')->validate();                         // true
Identum::cep('78000-000')->validate();                           // true
Identum::cns('100000000060018')->validate();                     // true
Identum::pis('329.9506.158-9')->validate();                      // true
Identum::ie('343.173.196.450', StateEnum::SP)->validate();       // true — all 27 states
Identum::renavam('60390908553')->validate();                     // true
Identum::placa('ABC1D23')->validate();                           // true — Mercosul format
Identum::tituloEleitor('123456781295')->validate();              // true

// Validate or throw
try {
    Identum::cpf('000.000.000-00')->validateOrFail();
} catch (ValidationException $e) {
    // handle invalid document
}

// Blacklist / whitelist
Identum::cpf('529.982.247-25')->blacklist(['529.982.247-25'])->validate(); // false
Identum::cpf('000.000.000-00')->whitelist(['000.000.000-00'])->validate(); // true
```

Direct instantiation
--------------------

[](#direct-instantiation)

```
use SafeAccess\Identum\Assets\CPF\CPFValidation;

$validator = CPFValidation::make('529.982.247-25');
$validator->validate(); // true
```

API
---

[](#api)

All validator classes share the same fluent interface after construction:

```
$v = Identum::cpf('52998224725'); // or CPFValidation::make('52998224725')

$v->validate();                                  // bool
$v->validateOrFail();                            // bool — throws ValidationException if invalid
$v->blacklist(['52998224725'])->validate();       // bool — force-reject these values
$v->whitelist(['00000000000'])->validate();       // bool — force-accept these values
```

MethodReturnDescription`validate()``bool`Returns `true` if valid, `false` otherwise`validateOrFail()``bool`Returns `true` if valid, throws `ValidationException` otherwise`blacklist(string[])``static`Force-reject the specified values regardless of checksum`whitelist(string[])``static`Force-accept the specified values regardless of checksumSupported documents
-------------------

[](#supported-documents)

DocumentAliasClassCPF`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`### IE — all 27 states

[](#ie--all-27-states)

```
use SafeAccess\Identum\Assets\IE\StateEnum;

Identum::ie('153189458', StateEnum::BA)->validate();    // Bahia — Mod-10/11 dual
Identum::ie('7908930932562', StateEnum::MG)->validate(); // Minas Gerais
Identum::ie('P199163724045', StateEnum::SP)->validate(); // São Paulo rural (P prefix)
```

### CNPJ — alfanumérico

[](#cnpj--alfanumérico)

```
Identum::cnpj('A0000000000032')->validate(); // true — alphanumeric CNPJ
```

Contributing
------------

[](#contributing)

See [CONTRIBUTING.md](../../CONTRIBUTING.md) for development setup, commit conventions, and pull request guidelines.

License
-------

[](#license)

[MIT](../../LICENSE) © Felipe Sauer

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance90

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~8 days

Total

8

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fdeabba51abd2977cc902752d741b7e905d3510702fe580532f8c16ed9bb5790?d=identicon)[felipesauer](/maintainers/felipesauer)

---

Top Contributors

[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")[![felipesauer](https://avatars.githubusercontent.com/u/120697114?v=4)](https://github.com/felipesauer "felipesauer (3 commits)")

---

Tags

brazilian-documentscnpjcpfiepestphpvalidationvalidationdocumentcpfcnpjbraziliansafeaccessidentum

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/safeaccess-identum/health.svg)

```
[![Health](https://phpackages.com/badges/safeaccess-identum/health.svg)](https://phpackages.com/packages/safeaccess-identum)
```

###  Alternatives

[beberlei/assert

Thin assertion library for input validation in business models.

2.4k101.9M636](/packages/beberlei-assert)[osteel/openapi-httpfoundation-testing

Validate HttpFoundation requests and responses against OpenAPI (3+) definitions

1202.1M7](/packages/osteel-openapi-httpfoundation-testing)[robersonfaria/validation

Pacote Laravel para validações comuns ao Brasil(pt-BR) tipo: CNPJ,CPF,CEP,CNS

107.6k](/packages/robersonfaria-validation)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
