antevemus / aspecification-br
Brazilian documents for antevemus/aspecification: CPF, CNPJ (alphanumeric too), CEP, phone, vehicle plate, CNJ process, CNH, PIS/PASEP, voter ID, RENAVAM and PIX key, with check digits, exact forms, codec names and failures that never echo the value
Package info
github.com/antevemus-it/Antevemus.ASpecificationBr
pkg:composer/antevemus/aspecification-br
Requires
- php: ^8.2
- antevemus/aspecification: ^2.13
Requires (Dev)
- infection/infection: ^0.31.9 || ^0.35.6
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
The Brazilian documents satellite of ASpecification for PHP 8.2+. Leaf specifications for CPF, CNPJ (numeric and alphanumeric), CEP, phone number, vehicle plate (legacy and Mercosur), CNJ court process number, CNH, PIS/PASEP, voter registration number, RENAVAM and PIX key: check digits, the exact masked or unmasked form, a name for each one in the codec, and failure messages that never repeat the value under evaluation. They compose with the core's and, or, not and Spec::property().
Install with composer require antevemus/aspecification-br.
Quick Start
<?php declare(strict_types=1); use Antevemus\ASpecification\Spec; use Antevemus\ASpecificationBr\BrSpec; use Antevemus\ASpecificationBr\PhoneKind; // A party: a CPF or a CNPJ, a postal code and a mobile phone number. $party = Spec::property('document', BrSpec::cpf()->or(BrSpec::cnpj())) ->and(Spec::property('zip', BrSpec::cep())) ->and(Spec::property('phone', BrSpec::phone(PhoneKind::Mobile))); $party->isSatisfiedBy((object) ['document' => '529.982.247-25', 'zip' => '01310-100', 'phone' => '(11) 98765-4321']); // true $party->isSatisfiedBy((object) ['document' => '12.ABC.345/01DE-35', 'zip' => '01310100', 'phone' => '+55 11 98765-4321']); // true $party->isSatisfiedBy((object) ['document' => '529.982.247-26', 'zip' => '01310-100', 'phone' => '(11) 98765-4321']); // false
Documentation
The official documentation lives in docs/en (and in Portuguese, in docs/pt-BR); every PHP block of it runs in the test suite.
| Page | What it covers |
|---|---|
| Installation and quick start | Composer, the requirements and the Quick Start. |
| Forms, check digits and secrecy | The candidate, the masked and unmasked forms, what each check proves, the failure messages and the codec. |
| CPF and CNPJ | BrSpec::cpf(), BrSpec::cnpj() and the alphanumeric CNPJ. |
| CEP and phone number | BrSpec::cep(), BrSpec::phone() and the area codes. |
| Vehicle plate and CNJ process number | BrSpec::vehiclePlate() and BrSpec::cnjProcessNumber(). |
| CNH, PIS/PASEP, voter registration and RENAVAM | BrSpec::cnh(), BrSpec::pis(), BrSpec::voterId() and BrSpec::renavam(). |
| PIX keys | BrSpec::pixKey() and the kinds of key of the DICT. |
| Tests | The suite, the properties and the mutation testing. |
| Roadmap | What shipped and what may come. |
License
MIT, see LICENSE. Provenance in NOTICE.md; changes in CHANGELOG.md.