Skip to content

Refactor: Introduce ReportFilter DTO to replace multiple positional parameters in Reports controller #4561

Open

Description

@coderabbitai

Summary

Several methods in app/Controllers/Reports.php accept 4+ positional string parameters ($start_date, $end_date, $sale_type, $location_id, etc.), which is a pre-existing code smell flagged in the existing TODO comments.

Affected methods include (but are not limited to):

  • summary_sales()
  • summary_categories()
  • summary_customers()
  • summary_suppliers()
  • summary_items()
  • summary_employees()
  • summary_discounts()
  • graphical_summary_sales()
  • graphical_summary_items()
  • graphical_summary_categories()
  • graphical_summary_suppliers()
  • graphical_summary_employees()
  • detailed_sales()
  • detailed_receivings()
  • and others (~15+ methods total)

Proposed Solution

Introduce a ReportFilter value object / DTO at app/Entities/ReportFilter.php (namespace App\Entities, aligned with CodeIgniter 4 conventions):

<?php

namespace App\Entities;

class ReportFilter
{
    public function __construct(
        public readonly string $startDate,
        public readonly string $endDate,
        public readonly string $saleType   = 'all',
        public readonly string $locationId = 'all',
        public readonly int    $discountType = 0,
        public readonly string $entityId   = '',    // customer/employee/supplier/discount ID
        public readonly string $paymentType = 'all',
    ) {}
}

Then update all affected controller methods to accept ReportFilter $filter instead of individual positional parameters.

Why

  • Adding a new filter field (e.g., discount_type) does not break every call site
  • IDE autocompletion on the object vs. positional string arguments
  • Single place to validate/sanitize report inputs
  • Routes already unpack URL segments into an $inputs array internally — the object formalizes that

Notes

References

Activity

  1. objecttothis commented on Oct 25, 2026

    @objecttothis
    Member

    Claude Issue Checker Agent (cc @objecttothis)

    Investigated against current master.

    Status: Still present (refactor not done).

    app/Controllers/Reports.php still has all the described methods using multiple positional string/int parameters, exactly as the issue describes, e.g.:

    • summary_sales(string $start_date, string $end_date, string $sale_type, string $location_id = 'all') — with the pre-existing // TODO: Perhaps these need to be passed as an array? Too many parameters in the signature. comment still in place.
    • summary_categories(), summary_customers(), summary_suppliers(), summary_items(), summary_employees(), summary_discounts() (which also takes int $discount_type = 0), graphical_summary_sales(), graphical_summary_items(), graphical_summary_categories(), graphical_summary_suppliers(), graphical_summary_employees(), detailed_sales(), detailed_receivings(), and others all still take 4+ positional parameters, each building an $inputs array locally right after entry (marked // TODO: Duplicated Code throughout).

    There is no app/Entities/ directory in the codebase at all (app/ contains Commands, Common.php, Config, Controllers, Database, Events, Filters, Helpers, Language, Libraries, Models, ThirdParty, Views, index.html — no Entities), and a repo-wide search finds no ReportFilter class anywhere. No PR is currently linked to this issue. This remains an open, unimplemented refactor on master.

  2. objecttothis commented on Oct 28, 2026

    @objecttothis
    Member

    DTOs need to be put into /app/TransferObjects/[Domain]/ (e.g., /app/TransferObjects/Cashups/CashupAmounts.php), not /app/Entities/. Entities are DOs not DTOs.

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