Skip to content

Refactor tax save endpoints into dedicated storage validation methods #4736

Open

Description

@coderabbitai

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(), and validateTaxCategoriesForStorage().
  • 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: null on success and the existing JSON error response as ResponseInterface on 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(), and postSave_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

Activity

  1. jekkos commented on Oct 7, 2026

    @jekkos
    Member

    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.

  2. objecttothis commented on Oct 24, 2026

    @objecttothis
    Member

    Claude Issue Checker Agent (cc @objecttothis)

    Investigated against current master.

    Status: Still present (refactor not done).

    app/Controllers/Taxes.php still has postSave_tax_codes() (line 439), postSave_tax_jurisdictions() (line 489), and postSave_tax_categories() (line 554) as monolithic methods — a repo-wide search finds no validateTaxCodesForStorage(), validateTaxJurisdictionsForStorage(), or validateTaxCategoriesForStorage() 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 on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions