Repository navigation
Conversation
- 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
📝 WalkthroughWalkthroughA new abstract Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (1 warning, 2 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 | 🔴 CriticalCritical: 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 | 🔴 CriticalCritical: Wrong
$primaryKeyvalue and typed property declarations.Two issues here:
Bug:
$primaryKeyis set to'cashup_id'but this is theTax_jurisdictionmodel. Based on theexists(),get_info(), and other methods that use'jurisdiction_id', this should be'jurisdiction_id'.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 | 🔴 CriticalCritical: Remove type declarations from property overrides.
Same issue as flagged in other models — remove the
string,bool, andarraytype 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 | 🔴 CriticalCritical: Remove type declarations from property overrides.
Same issue as flagged in
Appconfig.php— these typed property declarations will cause a PHP fatal error becauseCodeIgniter\Modeldeclares these properties without types. Remove thestring,bool, andarraytype 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 | 🔴 CriticalCritical: 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
📒 Files selected for processing (29)
app/Models/Appconfig.phpapp/Models/Attribute.phpapp/Models/BaseModel.phpapp/Models/Cashup.phpapp/Models/Customer.phpapp/Models/Customer_rewards.phpapp/Models/Dinner_table.phpapp/Models/Employee.phpapp/Models/Expense.phpapp/Models/Expense_category.phpapp/Models/Giftcard.phpapp/Models/Inventory.phpapp/Models/Item.phpapp/Models/Item_kit.phpapp/Models/Item_kit_items.phpapp/Models/Item_quantity.phpapp/Models/Item_taxes.phpapp/Models/Module.phpapp/Models/Person.phpapp/Models/Receiving.phpapp/Models/Reports/Report.phpapp/Models/Rewards.phpapp/Models/Sale.phpapp/Models/Stock_location.phpapp/Models/Supplier.phpapp/Models/Tax.phpapp/Models/Tax_category.phpapp/Models/Tax_code.phpapp/Models/Tax_jurisdiction.php
…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
There was a problem hiding this comment.
🧹 Nitpick comments (1)
app/Models/Tokens/Token.php (1)
12-12: Retain thestringtype declaration on$value.Unlike the other model property edits in this PR (which were untyped to avoid conflicts with
CodeIgniter\Model's untyped declarations),$valueis a property introduced byTokenitself — not inherited fromCodeIgniter\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
📒 Files selected for processing (28)
app/Models/Appconfig.phpapp/Models/Attribute.phpapp/Models/Cashup.phpapp/Models/Customer.phpapp/Models/Customer_rewards.phpapp/Models/Dinner_table.phpapp/Models/Employee.phpapp/Models/Expense.phpapp/Models/Expense_category.phpapp/Models/Giftcard.phpapp/Models/Inventory.phpapp/Models/Item.phpapp/Models/Item_kit.phpapp/Models/Item_kit_items.phpapp/Models/Item_quantity.phpapp/Models/Item_taxes.phpapp/Models/Module.phpapp/Models/Person.phpapp/Models/Receiving.phpapp/Models/Rewards.phpapp/Models/Sale.phpapp/Models/Stock_location.phpapp/Models/Supplier.phpapp/Models/Tax.phpapp/Models/Tax_category.phpapp/Models/Tax_code.phpapp/Models/Tax_jurisdiction.phpapp/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
Summary
BaseModelabstract class extendingCodeIgniter\Modelwith getter methodsgetTableName(),getPrimaryKeyName(),getAllowedFields(),getUseAutoIncrement(),getUseSoftDeletes()BaseModelinstead ofCodeIgniter\ModelChanges
New File
app/Models/BaseModel.php- Base class with property gettersUpdated Models
All models now extend
BaseModel:Design Notes
Properties remain
protected(notprivate) because:privatewould break CI4 functionalityRelated
Closes #4489
Summary by CodeRabbit