Skip to content

Update library for latest PHP version#12

Merged
tavo1987 merged 10 commits into
masterfrom
claude/update-php-library-kf05b
Jan 7, 2026
Merged

Update library for latest PHP version#12
tavo1987 merged 10 commits into
masterfrom
claude/update-php-library-kf05b

Conversation

@tavo1987

@tavo1987 tavo1987 commented Jan 7, 2026

Copy link
Copy Markdown
Owner

This pull request modernizes the Ecuadorian ID and RUC validator library by updating its documentation, package configuration, and test suite to improve usability, maintainability, and compliance with current PHP standards. The most significant changes include raising the minimum PHP version requirement, updating documentation for clarity and English language usage, adding comprehensive tests for cedula and RUC validation (including foreign resident support), and aligning the package and test configurations with best practices.

Documentation and API Modernization:

  • The readme.md has been fully rewritten in English, providing clearer usage instructions, detailed API documentation, and comprehensive explanations of document structure, validation logic, and limitations. The documentation now highlights the new English method names, constants, and the universal validate() method, and includes explicit support for province code 30 (foreign residents).

Composer and Package Configuration Updates:

  • composer.json now requires PHP 8.1 or higher, updates the PHPUnit requirement to ^10.0|^11.0, adds relevant keywords, updates author information, and enables stable package preference and sorted dependencies. [1] [2] [3]

Test Suite Improvements:

  • The PHPUnit configuration (phpunit.xml) is updated for compatibility with PHPUnit 10+, including schema validation, new options for execution order and reporting, and a modernized source inclusion structure.
  • New comprehensive test classes are introduced:
    • tests/CedulaValidationTest.php covers all edge cases for cedula validation, including invalid input, valid cases across provinces, and special handling for province code 30 (foreign residents).
    • tests/NaturalPersonRucValidationTest.php provides similar coverage for natural person RUC validation, including establishment code checks and foreign resident support.

These changes collectively ensure the library is robust, well-documented, and ready for modern PHP environments.

claude and others added 10 commits January 7, 2026 19:52
Breaking Changes:
- Minimum PHP version is now 8.1
- Updated PHPUnit to version 10/11

New Features:
- Added validar() method for auto-detecting document type (cedula/RUC)
- Added getTipoDocumento() method to get the detected document type
- Added support for province code 30 (Ecuadorians abroad/foreign residents)
- For code 30, third digit validation is skipped (addresses PR #6)
- Added PHP 8.x type hints, return types, and match expressions
- Added document type constants (TIPO_CEDULA, TIPO_RUC_NATURAL, etc.)

Bug Fixes:
- Issue #3: Documented that RUC 0962893970001 is mathematically invalid
  (check digit is 7 but should be 1). Added test to verify correct behavior.
- Issue #7: Verified switch case has proper breaks in validarTercerDigito()

Tests:
- Added 79 comprehensive tests (up from ~38)
- Added tests for province code 30 (foreign residents)
- Added tests for universal validation method
- Added edge case tests for all document types

Documentation:
- Translated README to English
- Added complete province code list
- Added validation limitations section
- Added changelog for v2.0.0
Translate all Spanish error messages to English for consistency:
- Value cannot be empty
- Value can only contain digits
- Value must have X characters
- Province code (first two digits) must be between 01-24 or 30
- Third digit must be between 0 and 5 for cedula and natural person RUC
- Third digit must be 9 for private companies
- Third digit must be 6 for public companies
- Establishment code cannot be 0
- Check digit validation failed
- Invalid identification type

Updated all 5 test files to match the new English messages.
All 79 tests pass.
Breaking Changes:
- Constants renamed: TIPO_* → TYPE_*
- Method names now in English (legacy Spanish methods deprecated)

New Method Names:
- validate() - auto-detect and validate any document
- validateCedula() - validate Cedula
- validateNaturalPersonRuc() - validate Natural Person RUC
- validatePrivateCompanyRuc() - validate Private Company RUC
- validatePublicCompanyRuc() - validate Public Company RUC
- getDocumentType() - get detected document type

Code Improvements:
- Class marked as final
- Private internal validation methods (perform*)
- Constants for coefficients and magic numbers
- Match expressions for cleaner conditionals
- Removed code duplication
- All variable names in English
- Comprehensive PHPDoc comments

Test Improvements:
- All test files renamed to English
- Test method names in English
- 77 tests with 162 assertions

Legacy Support:
- All Spanish method names still work (@deprecated)
- Backwards compatible for existing users
Breaking changes for v2.0.0:
- Removed validar() - use validate()
- Removed validarCedula() - use validateCedula()
- Removed validarRucPersonaNatural() - use validateNaturalPersonRuc()
- Removed validarRucSociedadPrivada() - use validatePrivateCompanyRuc()
- Removed validarRucSociedadPublica() - use validatePublicCompanyRuc()
- Removed getTipoDocumento() - use getDocumentType()

This is a clean v2.0 release with no backwards compatibility.
Co-authored-by: StyleCI Bot <bot@styleci.io>
- Run tests on PHP 8.1, 8.2, 8.3, 8.4
- Trigger on push and PR to main/master
- Add static validation methods for quick checks without instantiation:
  - isValid() for any document type
  - isValidCedula(), isValidNaturalPersonRuc(), etc.
- Add extractCedulaFromRuc() to extract cedula from natural person RUC
- Update README with comprehensive v2.0.0 documentation
- Add 16 new tests (total: 93 tests)
Co-authored-by: StyleCI Bot <bot@styleci.io>
@tavo1987 tavo1987 merged commit e5b6549 into master Jan 7, 2026
5 of 6 checks passed
@tavo1987 tavo1987 deleted the claude/update-php-library-kf05b branch January 7, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants