-
Notifications
You must be signed in to change notification settings - Fork 0
[v2][cnpj-val] Upgrade to latest API and add support to alphanumeric CNPJ format
#43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2d2b8f4
docs(cnpj-val): create changelog for v1
juliolmuller b05b893
chore: disable linting rule
juliolmuller 4075ed4
chore(cnpj-val): setup Pest over PhpUnit
juliolmuller 0e04118
chore(cnpj-val): update package description
juliolmuller 31abe24
feat(cnpj-val): update package namespaces
juliolmuller 4bc3541
chore(cnpj-val): define package dependencies
juliolmuller 15eb7d5
feat(cnpj-val): create specific exceptions and errors for package
juliolmuller 4f21d3d
feat(cnpj-val): create options manager for validator
juliolmuller dc49f5d
feat(cnpj-val): update validator
juliolmuller 824f178
feat(cnpj-val): update helper
juliolmuller e429231
test(cnpj-val): add unit tests with Pest notation
juliolmuller 7a917ca
test(cnpj-val): drop legacy tests
juliolmuller 632ed1c
docs(cnpj-val): update README for v2
juliolmuller 5b8586d
docs(cnpj-val): create Portuguese version of README
juliolmuller ac7287b
docs(cnpj-val): update CHANGELOG with v2
juliolmuller a38adf1
chore(cnpj-val): drop unused dependency
juliolmuller 01c9b43
test(cnpj-val): fix erroneous option name
juliolmuller 21fce3c
perf(cnpj-val): optimize options instantiation
juliolmuller 8677f11
perf(cnpj-val): replace multibyte string method
juliolmuller 84bf18f
perf(cnpj-val): replace REGEX test by byte comparison
juliolmuller a8176f9
perf(cnpj-val): replace string concatenation by array appending
juliolmuller 5463ab7
perf(cnpj-val): optimize instantiation of validator on helper function
juliolmuller 0bfca6d
docs(cnpj-val): update documentations with key performance improvements
juliolmuller c60c047
docs(cnpj-val): fix subject-verb agreement
juliolmuller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # lacus/cnpj-val | ||
|
|
||
| ## 2.0.0 | ||
|
|
||
| ### 🎉 v2 at a glance 🎊 | ||
|
|
||
| - 🆕 **Alphanumeric CNPJ** — Full support for the new [14-character alphanumeric CNPJ](https://www.gov.br/receitafederal/pt-br/assuntos/noticias/2023/julho/cnpj-alfa-numerico) (digits and letters). | ||
| - ⚙️ **`CnpjValidatorOptions`** — Configure `type` (`numeric` vs `alphanumeric`) and `caseSensitive` on the instance or per `isValid()` call. | ||
| - 🛡️ **Structured errors** — Typed exceptions (`CnpjValidatorTypeError`, `CnpjValidatorException` and their subclasses) for clearer error handling. | ||
|
|
||
| ### BREAKING CHANGES | ||
|
|
||
| - **Namespace migration** — Public API moved from `Lacus\CnpjVal\` to `Lacus\BrUtils\Cnpj\`; update `use` imports for `CnpjValidator`, `CnpjValidatorOptions`, `CnpjValidationType`, and `cnpj_val()`. | ||
| - **Drop support to PHP v8.1**: Minimum version for the package is now **PHP 8.2** (`^8.2`). It may even run forcedly in earlier versions, but it's not recommended to keep running stale versions of PHP in production. | ||
| - **`CNPJ_LENGTH` constant** — Removed from `cnpj-val.php`; use `CnpjValidatorOptions::CNPJ_LENGTH` instead. | ||
| - **Default character set** — Default validation is **alphanumeric** (letters are kept after sanitization). For legacy numeric-only behavior, pass `type: 'numeric'` or `CnpjValidationType::Numeric`. | ||
| - **`cnpj_val()` / `isValid()` signatures** — Accept `string|list<string>` and optional `CnpjValidatorOptions` (or named `type` / `caseSensitive`); v1 accepted only a single `string`. | ||
| - **Invalid input** — Non-string / non–`string[]` values throw `CnpjValidatorInputTypeError` instead of a native `TypeError`. | ||
| - **Check-digit engine** — Validation delegates to `CnpjCheckDigits` from **`lacus/cnpj-dv`** `^1.1` (v1 calculated digits inline via `CnpjGeneratorVerifierDigit` from **`lacus/cnpj-gen`** only). | ||
|
|
||
| ### New features | ||
|
|
||
| - **`CnpjValidatorOptions`** — Options object with property access, `getAll()`, `set()`, and `overrides` merging (constructor and per-call). | ||
| - **`CnpjValidationType`** — Backed enum (`Alphanumeric`, `Numeric`) for the `type` option. | ||
| - **`caseSensitive` option** — When `false`, lowercase letters are uppercased before alphanumeric validation. | ||
| - **`getOptions()`** — Returns the shared default `CnpjValidatorOptions` instance used by `CnpjValidator`. | ||
| - **Array input** — `isValid()` and `cnpj_val()` concatenate a `list<string>` (e.g. grouped or formatted segments). | ||
| - **Verifier-digit rule** — Rejects CNPJs whose last two characters are not digits (`0`–`9`). | ||
| - **Exception hierarchy** — `CnpjValidatorInputTypeError`, `CnpjValidatorOptionsTypeError`, `CnpjValidatorOptionTypeInvalidException`, plus `getName()` on base error classes. | ||
|
|
||
| ### Improvements | ||
|
|
||
| - **`cnpj_val()` reuse** — The instance of `CnpjValidator` is kept alive and reused across multiple calls. | ||
| - **Dependency alignment**: now depends on `lacus/cnpj-dv` and `lacus/utils`. | ||
| - **Autoload alignment**: package autoload namespace updated to the BR Utils standard. | ||
| - **Docs refresh**: English and pt-BR READMEs updated with v2 API and usage guidance. | ||
|
|
||
| ## 1.0.0 | ||
|
|
||
| ### Stable v1 API | ||
|
|
||
| First stable release of **`lacus/cnpj-val`** focused on CNPJ checksum validation. | ||
|
|
||
| - **API namespace**: `Lacus\CnpjVal\`. | ||
| - **Main resources**: | ||
| - `cnpj_val()` | ||
| - `CnpjValidator` | ||
| - `CNPJ_LENGTH` | ||
| - **Validation scope**: | ||
| - 14-digit CNPJ with first and second verifier digits checked against the official algorithm. | ||
| - Masked or plain input supported by stripping non-digits before validation. | ||
| - **Verifier digits**: | ||
| - Calculations reuse `CnpjGeneratorVerifierDigit` from **`lacus/cnpj-gen`** `^1.0`. | ||
| - **Return model**: | ||
| - Ordinary validation failures return `false` (no exceptions for invalid CNPJ). | ||
| - **Runtime**: | ||
| - PHP `>=8.1`. | ||
| - **Testing**: | ||
| - PHPUnit-based suite. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.