Skip to content

refactor: Add getters for protected model properties - #4504

Open
jekkos wants to merge 2 commits into
masterfrom
refactor-4489-model-getters
Open

jekkos wants to merge 2 commits into
masterfrom
refactor-4489-model-getters

Conversation

@jekkos

@jekkos jekkos commented Apr 15, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Created BaseModel abstract class extending CodeIgniter\Model with getter methods
  • Added getters: getTableName(), getPrimaryKeyName(), getAllowedFields(), getUseAutoIncrement(), getUseSoftDeletes()
  • Updated all 27+ models to extend BaseModel instead of CodeIgniter\Model
  • Added PHP 8.1+ type declarations to model properties

Changes

New File

  • app/Models/BaseModel.php - Base class with property getters

Updated Models

All models now extend BaseModel:

  • Person (base for Employee, Customer, Supplier)
  • Item, Appconfig, Attribute, Cashup, Dinner_table
  • Expense, Expense_category, Giftcard, Inventory
  • Item_kit, Item_kit_items, Item_quantity, Item_taxes
  • Module, Receiving, Rewards, Sale, Stock_location
  • Tax, Tax_category, Tax_code, Tax_jurisdiction
  • Customer_rewards, Reports/Report

Design Notes

Properties remain protected (not private) because:

  • CodeIgniter 4's Model class needs to access these properties internally
  • Changing to private would break CI4 functionality
  • Getters provide controlled external access without breaking CI4

Related

Closes #4489

Summary by CodeRabbit

  • Refactor
    • Consolidated and standardized model foundations and type declarations for greater consistency and maintainability.
    • Minor metadata corrections and cleanup across models (e.g., table/primary-key metadata adjustments and docblock removals).
    • No changes to public method behavior or user-facing functionality.

- Create BaseModel with getters for $table, $primaryKey, $allowedFields
- All models now extend BaseModel instead of CodeIgniter\Model
- Add type declarations to protected properties

Closes #4489
@coderabbitai

coderabbitai Bot commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A new abstract App\Models\BaseModel was added exposing getters for common protected model configuration properties. Numerous model classes (≈31) were updated to extend BaseModel instead of CodeIgniter\Model; several models also received explicit typed property declarations or small property edits. No method bodies or public signatures were functionally changed.

Changes

Cohort / File(s) Summary
New BaseModel Foundation
app/Models/BaseModel.php
Added abstract class extending CodeIgniter\Model with public getters: getTableName(), getPrimaryKeyName(), getAllowedFields(), getUseAutoIncrement(), getUseSoftDeletes().
Bulk model inheritance updates
app/Models/...
app/Models/Appconfig.php, app/Models/Attribute.php, app/Models/Cashup.php, app/Models/Dinner_table.php, app/Models/Expense.php, app/Models/Expense_category.php, app/Models/Giftcard.php, app/Models/Inventory.php, app/Models/Item.php, app/Models/Item_kit.php, app/Models/Item_kit_items.php, app/Models/Item_quantity.php, app/Models/Item_taxes.php, app/Models/Module.php, app/Models/Receiving.php, app/Models/Rewards.php, app/Models/Sale.php, app/Models/Stock_location.php, app/Models/Tax.php, app/Models/Tax_category.php, app/Models/Tax_code.php
Replaced extends CodeIgniter\Model with extends BaseModel and removed use CodeIgniter\Model; imports; several files also added explicit typed declarations for $table, $primaryKey, $useAutoIncrement, $useSoftDeletes, and $allowedFields.
Models with docblock or small property edits
app/Models/Customer.php, app/Models/Customer_rewards.php, app/Models/Employee.php, app/Models/Item_taxes.php, app/Models/Item_kit_items.php, app/Models/Person.php, app/Models/Supplier.php, app/Models/Tax_jurisdiction.php, app/Models/Tokens/Token.php
Removed/cleaned class docblocks, adjusted model $table/$primaryKey where noted (e.g., customer_packages→customers_packages, cashup_id→jurisdiction_id), and one token property had its type removed; method logic and signatures preserved.
Report abstract class update
app/Models/Reports/Report.php
Changed abstract Report to extend App\Models\BaseModel (from CodeIgniter\Model) and removed docblock comments; abstract method signatures unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

enhancement

🐰
I hopped in the code with a twitch of my nose,
BaseModel sprouts getters where the wild metadata grows;
Models lined up like carrots in rows,
Typed and tidy where soft-deletes doze,
A small rabbit cheer for these tidy repose. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The PR partially addresses #4489: getters are implemented and models refactored to use BaseModel, but properties remain protected rather than private, and calling code refactoring/tests are not included. Verify if keeping properties protected (vs. private) aligns with issue requirements, and confirm whether refactoring calling code and adding tests are separate work items.
Out of Scope Changes check ❓ Inconclusive Most changes directly support the PR objective, but Token.php property type removal and Tax_jurisdiction primaryKey/Customer_rewards table changes appear tangential to the core getter refactoring goal. Clarify whether Token.php type removal, Tax_jurisdiction primaryKey fix, and Customer_rewards table name correction are related to issue #4489 or separate bug fixes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding getter methods for protected model properties via a new BaseModel class.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor-4489-model-getters

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (5)
app/Models/Employee.php (1)

12-23: ⚠️ Potential issue | 🔴 Critical

Critical: Remove type declarations from property overrides.

Same issue as flagged in other models — remove the type hints to avoid the PHP fatal error.

🐛 Proposed fix
-    protected string $table = 'Employees';
-    protected string $primaryKey = 'person_id';
-    protected bool $useAutoIncrement = false;
-    protected bool $useSoftDeletes = false;
-    protected array $allowedFields = [
+    protected $table = 'Employees';
+    protected $primaryKey = 'person_id';
+    protected $useAutoIncrement = false;
+    protected $useSoftDeletes = false;
+    protected $allowedFields = [
         'username',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Models/Employee.php` around lines 12 - 23, The property overrides in the
Employee model (properties $table, $primaryKey, $useAutoIncrement,
$useSoftDeletes, and $allowedFields) must not declare types; remove the type
declarations so they are plain untyped properties matching the base Model
signature—update these declarations in the Employee class to remove "string",
"bool", and "array" type hints and leave the same names and initial values
intact.
app/Models/Tax_jurisdiction.php (1)

10-22: ⚠️ Potential issue | 🔴 Critical

Critical: Wrong $primaryKey value and typed property declarations.

Two issues here:

  1. Bug: $primaryKey is set to 'cashup_id' but this is the Tax_jurisdiction model. Based on the exists(), get_info(), and other methods that use 'jurisdiction_id', this should be 'jurisdiction_id'.

  2. Fatal error: Same typed property declaration issue as other models — remove the type hints.

🐛 Proposed fix
-    protected string $table = 'tax_jurisdictions';
-    protected string $primaryKey = 'cashup_id';
-    protected bool $useAutoIncrement = true;
-    protected bool $useSoftDeletes = false;
-    protected array $allowedFields = [
+    protected $table = 'tax_jurisdictions';
+    protected $primaryKey = 'jurisdiction_id';
+    protected $useAutoIncrement = true;
+    protected $useSoftDeletes = false;
+    protected $allowedFields = [
         'jurisdiction_name',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Models/Tax_jurisdiction.php` around lines 10 - 22, In the
Tax_jurisdiction model, change the incorrect protected $primaryKey value from
'cashup_id' to 'jurisdiction_id' to match usages in exists(), get_info(), and
other methods, and remove the typed property declarations (e.g., remove "string"
and "bool" type hints on properties like $table, $primaryKey, $useAutoIncrement,
$useSoftDeletes, $allowedFields) so the class uses untyped properties consistent
with other models.
app/Models/Customer.php (1)

11-29: ⚠️ Potential issue | 🔴 Critical

Critical: Remove type declarations from property overrides.

Same issue as flagged in other models — remove the string, bool, and array type hints to avoid the PHP fatal error.

🐛 Proposed fix
-    protected string $table = 'customers';
-    protected string $primaryKey = 'person_id';
-    protected bool $useAutoIncrement = false;
-    protected bool $useSoftDeletes = false;
-    protected array $allowedFields = [
+    protected $table = 'customers';
+    protected $primaryKey = 'person_id';
+    protected $useAutoIncrement = false;
+    protected $useSoftDeletes = false;
+    protected $allowedFields = [
         'account_number',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Models/Customer.php` around lines 11 - 29, In the Customer model remove
the PHP type hints from the property overrides so they match the framework's
expected declarations: replace declarations like protected string $table,
protected string $primaryKey, protected bool $useAutoIncrement, protected bool
$useSoftDeletes, and protected array $allowedFields with untyped properties
(e.g., protected $table, protected $primaryKey, protected $useAutoIncrement,
protected $useSoftDeletes, protected $allowedFields) keeping the same values and
visibility; update only these properties in the Customer class to avoid the PHP
fatal error caused by typed property overrides.
app/Models/Giftcard.php (1)

10-20: ⚠️ Potential issue | 🔴 Critical

Critical: Remove type declarations from property overrides.

Same issue as flagged in Appconfig.php — these typed property declarations will cause a PHP fatal error because CodeIgniter\Model declares these properties without types. Remove the string, bool, and array type hints.

🐛 Proposed fix
-    protected string $table = 'giftcards';
-    protected string $primaryKey = 'giftcard_id';
-    protected bool $useAutoIncrement = true;
-    protected bool $useSoftDeletes = false;
-    protected array $allowedFields = [
+    protected $table = 'giftcards';
+    protected $primaryKey = 'giftcard_id';
+    protected $useAutoIncrement = true;
+    protected $useSoftDeletes = false;
+    protected $allowedFields = [
         'giftcard_number',
         'value',
         'deleted',
         'person_id',
         'record_time'
     ];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Models/Giftcard.php` around lines 10 - 20, The property overrides in the
Giftcard model (properties $table, $primaryKey, $useAutoIncrement,
$useSoftDeletes, $allowedFields) are declared with PHP types which conflict with
CodeIgniter\Model's untyped declarations; remove the type hints
(string/bool/array) from these property declarations in the Giftcard class so
they match the parent class signatures while keeping the same property names and
values.
app/Models/Supplier.php (1)

9-20: ⚠️ Potential issue | 🔴 Critical

Critical: Remove type declarations from property overrides.

Same issue as flagged in other models — remove the type hints to avoid the PHP fatal error.

🐛 Proposed fix
-    protected string $table = 'suppliers';
-    protected string $primaryKey = 'person_id';
-    protected bool $useAutoIncrement = false;
-    protected bool $useSoftDeletes = false;
-    protected array $allowedFields = [
+    protected $table = 'suppliers';
+    protected $primaryKey = 'person_id';
+    protected $useAutoIncrement = false;
+    protected $useSoftDeletes = false;
+    protected $allowedFields = [
         'company_name',
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Models/Supplier.php` around lines 9 - 20, The class property overrides in
Supplier (properties $table, $primaryKey, $useAutoIncrement, $useSoftDeletes,
$allowedFields) include PHP type declarations which cause a fatal error; remove
the type hints so the properties are declared without types (e.g. use protected
$table, protected $primaryKey, protected $useAutoIncrement, protected
$useSoftDeletes, protected $allowedFields) and keep their existing values to
match the parent model contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/Models/Customer_rewards.php`:
- Around line 9-10: The model's $table metadata is incorrect (set to
'customer_packages') which will break getter/BaseModel table resolution; update
the Customer_rewards model to set protected string $table = 'customers_packages'
(keeping protected string $primaryKey = 'package_id' as-is) so all queries and
getter-based access resolve to the proper table name, then run tests or a quick
query against the Customer_rewards class to verify correct table resolution.

In `@app/Models/Item_taxes.php`:
- Around line 7-11: Remove the typed redeclarations of inherited Model
properties in the Item_taxes model: drop the type hints (or remove the property
lines entirely) for $table, $primaryKey, $useAutoIncrement, $useSoftDeletes, and
$allowedFields in the App\Models\Item_taxes class so they match the untyped
definitions from CodeIgniter's Model/BaseModel; keep the same property names and
values if needed but declare them without type annotations (or omit them to
inherit) to avoid the PHP fatal type conflict.

---

Outside diff comments:
In `@app/Models/Customer.php`:
- Around line 11-29: In the Customer model remove the PHP type hints from the
property overrides so they match the framework's expected declarations: replace
declarations like protected string $table, protected string $primaryKey,
protected bool $useAutoIncrement, protected bool $useSoftDeletes, and protected
array $allowedFields with untyped properties (e.g., protected $table, protected
$primaryKey, protected $useAutoIncrement, protected $useSoftDeletes, protected
$allowedFields) keeping the same values and visibility; update only these
properties in the Customer class to avoid the PHP fatal error caused by typed
property overrides.

In `@app/Models/Employee.php`:
- Around line 12-23: The property overrides in the Employee model (properties
$table, $primaryKey, $useAutoIncrement, $useSoftDeletes, and $allowedFields)
must not declare types; remove the type declarations so they are plain untyped
properties matching the base Model signature—update these declarations in the
Employee class to remove "string", "bool", and "array" type hints and leave the
same names and initial values intact.

In `@app/Models/Giftcard.php`:
- Around line 10-20: The property overrides in the Giftcard model (properties
$table, $primaryKey, $useAutoIncrement, $useSoftDeletes, $allowedFields) are
declared with PHP types which conflict with CodeIgniter\Model's untyped
declarations; remove the type hints (string/bool/array) from these property
declarations in the Giftcard class so they match the parent class signatures
while keeping the same property names and values.

In `@app/Models/Supplier.php`:
- Around line 9-20: The class property overrides in Supplier (properties $table,
$primaryKey, $useAutoIncrement, $useSoftDeletes, $allowedFields) include PHP
type declarations which cause a fatal error; remove the type hints so the
properties are declared without types (e.g. use protected $table, protected
$primaryKey, protected $useAutoIncrement, protected $useSoftDeletes, protected
$allowedFields) and keep their existing values to match the parent model
contract.

In `@app/Models/Tax_jurisdiction.php`:
- Around line 10-22: In the Tax_jurisdiction model, change the incorrect
protected $primaryKey value from 'cashup_id' to 'jurisdiction_id' to match
usages in exists(), get_info(), and other methods, and remove the typed property
declarations (e.g., remove "string" and "bool" type hints on properties like
$table, $primaryKey, $useAutoIncrement, $useSoftDeletes, $allowedFields) so the
class uses untyped properties consistent with other models.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 23552fa4-4ad4-401c-9722-90a7af4f84a8

📥 Commits

Reviewing files that changed from the base of the PR and between 165c335 and e17e85b.

📒 Files selected for processing (29)
  • app/Models/Appconfig.php
  • app/Models/Attribute.php
  • app/Models/BaseModel.php
  • app/Models/Cashup.php
  • app/Models/Customer.php
  • app/Models/Customer_rewards.php
  • app/Models/Dinner_table.php
  • app/Models/Employee.php
  • app/Models/Expense.php
  • app/Models/Expense_category.php
  • app/Models/Giftcard.php
  • app/Models/Inventory.php
  • app/Models/Item.php
  • app/Models/Item_kit.php
  • app/Models/Item_kit_items.php
  • app/Models/Item_quantity.php
  • app/Models/Item_taxes.php
  • app/Models/Module.php
  • app/Models/Person.php
  • app/Models/Receiving.php
  • app/Models/Reports/Report.php
  • app/Models/Rewards.php
  • app/Models/Sale.php
  • app/Models/Stock_location.php
  • app/Models/Supplier.php
  • app/Models/Tax.php
  • app/Models/Tax_category.php
  • app/Models/Tax_code.php
  • app/Models/Tax_jurisdiction.php

Comment thread app/Models/Customer_rewards.php Resolved
Comment thread app/Models/Item_taxes.php Resolved
…y bug

- Remove PHP type declarations from model property overrides to prevent fatal errors (CI4 Model declares without types)
- Fix wrong $primaryKey in Tax_jurisdiction (was 'cashup_id', now 'jurisdiction_id')
- Fix wrong $table in Customer_rewards (was 'customer_packages', now 'customers_packets')

Addresses CodeRabbit review comments

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
app/Models/Tokens/Token.php (1)

12-12: Retain the string type declaration on $value.

Unlike the other model property edits in this PR (which were untyped to avoid conflicts with CodeIgniter\Model's untyped declarations), $value is a property introduced by Token itself — not inherited from CodeIgniter\Model. The constructor signature (__construct(string $value = '')) and all subclass usage (Token_work_order_sequence, Token_invoice_sequence) treat it as a string, so there's no compatibility reason to drop the type. Removing it weakens type safety without benefit.

As per coding guidelines: "Write PHP 8.1+ compatible code with proper type declarations".

Proposed fix
-    protected $value = '';
+    protected string $value = '';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Models/Tokens/Token.php` at line 12, Restore the string type declaration
on the Token model's property by changing the declaration of $value back to a
typed property (i.e., protected string $value = ''), since Token defines and
uses this property directly (see class Token and its constructor
__construct(string $value = '') and subclasses Token_work_order_sequence /
Token_invoice_sequence); update the property declaration in Token.php to include
the string type to preserve type safety and remain PHP 8.1+ compliant.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@app/Models/Tokens/Token.php`:
- Line 12: Restore the string type declaration on the Token model's property by
changing the declaration of $value back to a typed property (i.e., protected
string $value = ''), since Token defines and uses this property directly (see
class Token and its constructor __construct(string $value = '') and subclasses
Token_work_order_sequence / Token_invoice_sequence); update the property
declaration in Token.php to include the string type to preserve type safety and
remain PHP 8.1+ compliant.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bdb34aba-ccdb-4027-9443-a34a5a433540

📥 Commits

Reviewing files that changed from the base of the PR and between e17e85b and 0a0a1e9.

📒 Files selected for processing (28)
  • app/Models/Appconfig.php
  • app/Models/Attribute.php
  • app/Models/Cashup.php
  • app/Models/Customer.php
  • app/Models/Customer_rewards.php
  • app/Models/Dinner_table.php
  • app/Models/Employee.php
  • app/Models/Expense.php
  • app/Models/Expense_category.php
  • app/Models/Giftcard.php
  • app/Models/Inventory.php
  • app/Models/Item.php
  • app/Models/Item_kit.php
  • app/Models/Item_kit_items.php
  • app/Models/Item_quantity.php
  • app/Models/Item_taxes.php
  • app/Models/Module.php
  • app/Models/Person.php
  • app/Models/Receiving.php
  • app/Models/Rewards.php
  • app/Models/Sale.php
  • app/Models/Stock_location.php
  • app/Models/Supplier.php
  • app/Models/Tax.php
  • app/Models/Tax_category.php
  • app/Models/Tax_code.php
  • app/Models/Tax_jurisdiction.php
  • app/Models/Tokens/Token.php
💤 Files with no reviewable changes (3)
  • app/Models/Supplier.php
  • app/Models/Employee.php
  • app/Models/Customer.php
✅ Files skipped from review due to trivial changes (4)
  • app/Models/Sale.php
  • app/Models/Appconfig.php
  • app/Models/Item_quantity.php
  • app/Models/Item_taxes.php
🚧 Files skipped from review as they are similar to previous changes (14)
  • app/Models/Giftcard.php
  • app/Models/Expense_category.php
  • app/Models/Rewards.php
  • app/Models/Cashup.php
  • app/Models/Stock_location.php
  • app/Models/Dinner_table.php
  • app/Models/Item_kit.php
  • app/Models/Expense.php
  • app/Models/Tax.php
  • app/Models/Tax_category.php
  • app/Models/Tax_code.php
  • app/Models/Attribute.php
  • app/Models/Module.php
  • app/Models/Person.php

This branch has not been deployed

No deployments
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.

[Technical Debt]: Add getters for protected model variables

2 participants