Refactor CNPJ validation: optimize storage and remove Reflection#42
Conversation
Removed ReflectionClass usage and simplified the getName method to directly extract the class name, improving performance and readability. Co-authored-by: Claude Opus <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude Opus <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude Opus <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor Agents <cursoragent@cursor.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRefactored CNPJ validation internals from array to string storage, removed Reflection usage from exception name extraction, updated tests to foreach-based cases, and documented the changes in the package changelog. No public API changes. ChangesCNPJ-DV Performance and API Alignment Refactor
Estimated code review effort🎯 4 (Complex) | ⏱️ ~65 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cnpj-dv/CHANGELOG.md`:
- Line 11: Update the CHANGELOG entry to reflect the actual shipped
implementation: remove or reword claims about a `private const WEIGHTS` lookup
table and `??=` memoization since `calculate()` still uses the factor-rolling
logic (the `factor === 9 ? 2 : factor + 1` style) and `getBoth()`/`getCnpj()`
still use explicit `if ($cache === null)` cache checks; mention the true
optimizations present (e.g., string-based internal representation, C-level
primitives, parseStringInput/parseArrayInput behavior) rather than the absent
WEIGHTS constant and null-coalescing assignment.
In `@packages/cnpj-dv/src/CnpjCheckDigits.php`:
- Around line 185-199: Update the parseArrayInput() PHPDoc to reflect that the
function can receive arrays with non-string elements so static analysis sees the
is_string check as reachable: change the `@param` annotation from list<string> to
list<mixed> (or array<mixed> / array<int,mixed>) above parseArrayInput(),
leaving the runtime guard and CnpjCheckDigitsInputTypeError throw intact; this
aligns the docblock with the actual contract of parseArrayInput() and removes
PHPStan false positives for the is_string($item) branch.
In `@packages/cnpj-dv/tests/Specs/CnpjCheckDigits.spec.php`:
- Around line 227-230: The test declares a local $invalid as (object) [...] but
annotates it with "@var mixed", causing a PHPStan conflict; edit the spec inside
the it('throws `CnpjCheckDigitsInputTypeError` for object input', ...) block and
either remove the "@var mixed" doc comment entirely or change it to a more
specific type like "@var stdClass $invalid" so the annotation matches the actual
object literal and PHPStan warning is resolved.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: c933d0d7-33f7-46fc-8ded-9b4443c4c5c2
📒 Files selected for processing (7)
packages/cnpj-dv/CHANGELOG.mdpackages/cnpj-dv/src/CnpjCheckDigits.phppackages/cnpj-dv/src/Exceptions/CnpjCheckDigitsException.phppackages/cnpj-dv/src/Exceptions/CnpjCheckDigitsTypeError.phppackages/cnpj-dv/tests/Specs/CnpjCheckDigits.spec.phppackages/cnpj-dv/tests/Specs/Exceptions.spec.phppackages/cnpj-dv/tests/Specs/Package.spec.php
Fix as per @coderabbitai review comment at #42 (comment). Co-authored-by: CodeRabbit <noreply@coderabbit.ai> Co-authored-by: Cursor <cursoragent@cursor.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cnpj-dv/CHANGELOG.md`:
- Line 11: The changelog paragraph is dense and must be converted into a clear,
bulleted entry and use Conventional Comments format (e.g., a "docs:" or "chore:"
prefix); split the single paragraph into bullets that call out the internal
representation change ($cnpjBase / CnpjCheckDigits), validator optimizations
(use of strlen, str_starts_with, substr, str_repeat), parsing improvements
(parseStringInput, parseArrayInput), retained BC behavior in calculate (array
$cnpjSequence and factor-rolling logic), caching behavior (getBoth, getCnpj with
explicit if ($cache === null) checks), and benchmark results, and ensure the
entry begins with the appropriate Conventional Comment tag.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 3bdd0561-a44e-4fdb-a7a5-969ce829e445
📒 Files selected for processing (1)
packages/cnpj-dv/CHANGELOG.md
Fix as per @coderabbitai review comment at #42 (comment). Co-authored-by: CodeRabbit <noreply@coderabbit.ai> Co-authored-by: Cursor <cursoragent@cursor.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Fix as per @coderabbitai review comment at LacusSolutions/br-utils-php#42 (comment). Co-authored-by: CodeRabbit <noreply@coderabbit.ai> Co-authored-by: Cursor <cursoragent@cursor.com>
Fix as per @coderabbitai review comment at LacusSolutions/br-utils-php#42 (comment). Co-authored-by: CodeRabbit <noreply@coderabbit.ai> Co-authored-by: Cursor <cursoragent@cursor.com>
Summary by CodeRabbit