Repository navigation
Open
Description
Summary
Extract endpoint-specific storage validation methods from the three tax save methods in app/Controllers/Taxes.php. Establish an incremental convention for controller validation without introducing a generic validation framework.
This is a separate follow-up to the tax-name validation fix in PR #4733. Requested by @jekkos.
Rationale
The save methods combine request handling, validation, row construction, persistence, and response formatting. Dedicated validation methods make the validation boundary explicit and reduce procedural code in the save methods.
Required changes
- Add
validateTaxCodesForStorage(),validateTaxJurisdictionsForStorage(), andvalidateTaxCategoriesForStorage(). - Pass explicit submitted data to each method. Document the fields each method validates.
- Confirm how
Secure_Controller::validateFields()obtains its input before adding a data parameter. Validate raw submitted names before HTML encoding. Retain the existing sanitized reads used for storage. - Use a consistent private-controller return contract:
nullon success and the existing JSON error response asResponseInterfaceon failure. - Move jurisdiction tax-group uniqueness validation out of row construction and into
validateTaxJurisdictionsForStorage(). - Validate parallel-array shapes and matching keys before indexing rows.
- Preserve the sequence: read input, validate, build rows, save, respond.
- Document the endpoint-specific validation convention. Keep database integrity guarantees in the persistence layer.
- Avoid expanding this task into a repository-wide controller refactor.
Affected areas
app/Controllers/Taxes.php:postSave_tax_codes(),postSave_tax_jurisdictions(), andpostSave_tax_categories().Secure_Controller::validateFields(): inspect its input contract and reuse it where appropriate.tests/Controllers/TaxesControllerTest.php: preserve and extend endpoint regression coverage.- Applicable contributor or controller conventions documentation.
Acceptance criteria
- Each tax save method delegates validation to its endpoint-specific method and returns validation errors before persistence.
- Existing JSON response formats and successful-save behavior remain unchanged.
- Tests cover blank names, legitimate Unicode and punctuation, rejected
<and>characters, names exceeding 255 characters, and batches containing both valid and invalid rows. - Tests cover malformed parallel arrays and mismatched keys with controlled validation errors rather than indexing errors.
- Tests preserve rejection of duplicate jurisdiction tax groups.
- Invalid batches do not persist rows.
- PHP changes follow the project's PHP 8.2+, CodeIgniter 4, and PSR-12 conventions.
- The refactor remains separate from PR fix(taxes): reject invalid characters in tax code, category, and jurisdiction names #4733.
References
Metadata
Metadata
Assignees
Labels
No labels
Activity
jekkos commentedon Oct 7, 2026
Also tracked here (related follow-up): @objecttothis asked that the local variables in these
postSave_*methods be brought in line with PSR-12 (camelCase) — see #4733 (comment). Keeping it with the validation-standard work so the Taxes.php refactor stays in one place.objecttothis commentedon Oct 24, 2026
Claude Issue Checker Agent (cc @objecttothis)
Investigated against current
master.Status: Still present (refactor not done).
app/Controllers/Taxes.phpstill haspostSave_tax_codes()(line 439),postSave_tax_jurisdictions()(line 489), andpostSave_tax_categories()(line 554) as monolithic methods — a repo-wide search finds novalidateTaxCodesForStorage(),validateTaxJurisdictionsForStorage(), orvalidateTaxCategoriesForStorage()anywhere in the codebase. Jurisdiction tax-group uniqueness validation also doesn't appear to have been extracted out of row construction into a dedicated method yet. This follow-up to PR #4733 has not been started/merged onmaster.