Download the PHP package lacus/cpf-dv without Composer
On this page you can find all versions of the php package lacus/cpf-dv. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package cpf-dv
Short Description Utility to calculate check digits on CPF (Brazilian Individual's Taxpayer ID)
License MIT
Homepage https://cpf-utils.vercel.app/
Informations about the package cpf-dv

A PHP utility to calculate check digits on CPF (Brazilian Individual's Taxpayer ID).
PHP Support
| Passing β | Passing β | Passing β | Passing β |
Features
- β
Flexible input: Accepts
stringorarrayof strings - β Format agnostic: Automatically strips non-numeric characters from string input
- β Auto-expansion: Multi-character strings in arrays are expanded to individual digits
- β Lazy evaluation: Check digits are calculated only when accessed (via properties)
- β Caching: Calculated values are cached for subsequent access
- β
Property-style API:
first,second,both,cpf(via magic__get) - β
Minimal dependencies: Only
lacus/utils - β
Error handling: Specific types for type, length, and invalid CPF scenarios (
TypeErrorvsExceptionsemantics)
Installation
Quick Start
Usage
The main resource of this package is the class CpfCheckDigits. Through an instance, you access CPF check-digit information:
__construct:new CpfCheckDigits(string|array $cpfInput)β 9β11 digits (formatting stripped from strings).first: First check digit (10th digit of the CPF). Lazy, cached.second: Second check digit (11th digit of the CPF). Lazy, cached.both: Both check digits concatenated as a string.cpf: The complete CPF as a string of 11 digits (9 base digits + 2 check digits).
Input formats
The CpfCheckDigits class accepts multiple input formats:
String input: plain digits or formatted CPF (e.g. 054.496.519-10). Non-numeric characters are automatically stripped. Use 9 digits (base only) or 11 digits (only the first 9 are used).
Array of strings: single-character strings or multi-character strings (expanded to individual digits), e.g. ['0','5','4','4','9','6','5','1','9'], ['054496519'], ['054','496','519'].
Errors & exceptions handling
This package uses TypeError vs Exception semantics: type errors indicate incorrect API use (e.g. wrong type); exceptions indicate invalid or ineligible data (e.g. invalid CPF). You can catch specific classes or use the abstract bases.
- CpfCheckDigitsTypeError (abstract) β base for type errors; extends PHPβs
TypeError - CpfCheckDigitsInputTypeError β input is not
stringorstring[] - CpfCheckDigitsException (abstract) β base for data/flow exceptions; extends
Exception - CpfCheckDigitsInputLengthException β sanitized length is not 9β11
- CpfCheckDigitsInputInvalidException β input ineligible (e.g. repeated digits like
111111111)
Other available resources
CPF_MIN_LENGTH:9β class constantCpfCheckDigits::CPF_MIN_LENGTH, and globalLacus\BrUtils\Cpf\CPF_MIN_LENGTHwhen the autoloadedcpf-dv.phpfile is loaded.CPF_MAX_LENGTH:11β class constantCpfCheckDigits::CPF_MAX_LENGTH, and globalLacus\BrUtils\Cpf\CPF_MAX_LENGTHwhencpf-dv.phpis loaded.
Calculation algorithm
The package calculates CPF check digits using the official Brazilian algorithm:
- First check digit (10th position): digits 1β9 of the CPF base; weights 10, 9, 8, 7, 6, 5, 4, 3, 2 (from left to right);
remainder = 11 - (sum(digit Γ weight) % 11); result is0if remainder > 9, otherwiseremainder. - Second check digit (11th position): digits 1β9 + first check digit; weights 11, 10, 9, 8, 7, 6, 5, 4, 3, 2 (from left to right); same formula.
Contribution & Support
We welcome contributions! Please see our Contributing Guidelines for details. If you find this project helpful, please consider:
- β Starring the repository
- π€ Contributing to the codebase
- π‘ Suggesting new features
- π Reporting bugs
License
This project is licensed under the MIT License β see the LICENSE file for details.
Changelog
See CHANGELOG for a list of changes and version history.
Made with β€οΈ by Lacus Solutions