Skip to content

[Technical Debt]: Unify signatures of model->save_value() functions #4459

Open

Description

@objecttothis

Type of Feature

✨ New Feature

OpensourcePOS Version

opensourcepos 3.3.9

Description

Currently some model save_value functions take the database primary key as an optional second parameter. Other require the ID as a second parameter. Given that the first parameter is the data array, we shouldn't need a second parameter at all. if the primary key id is populated in the data array then it should be checked to see if the object exists in the database then update if it does. If it doesn't exist or the primary key is not populated in the data array first parameter then the object should be inserted into the database.

  • Remove second parameter.
  • Refactor logic in save_value() functions to look for the primary key id in the data array and update/insert accordingly
  • Refactor calling code to properly call the functions
  • Refactor function naming to saveValue() for PSR compliance

Additional Information

No response

Verify you searched open requests in OpensourcePOS

  • I agree I have searched Open Requests

Activity

  1. objecttothis commented on Oct 25, 2026

    @objecttothis
    MemberAuthor

    Claude Issue Checker Agent (cc @objecttothis)

    Investigated against current master.

    Status: Still present (refactor not done).

    A repo-wide search for save_value( across app/Models/ confirms the inconsistency described is still there:

    • Item::save_value(array &$item_data, int $item_id = NEW_ENTRY): bool still carries the literal TODO // TODO: need to bring this in line with parent or change the name.
    • Some models take an optional second parameter defaulting to NEW_ENTRY (Person, Tax, Item_kit, Tax_category, Tax_jurisdiction, Item, Cashup), while others require it with no default (Dinner_table::save_value(array $table_data, int $dinner_table_id): bool, Item_quantity::save_value(array $location_detail, int $item_id, int $location_id): bool, Item_taxes::save_value(array &$items_taxes_data, int $item_id): bool, Customer_rewards::save_value(array $package_data, int $package_id): bool).
    • Rewards::save_value(array &$rewards_data, bool $rewards_id = false): bool even types its id parameter as bool rather than int.
    • None of these have been renamed to saveValue() for PSR-12 compliance, and none have been refactored to derive insert-vs-update purely from the primary key's presence in the data array — the id is still passed as an explicit second parameter everywhere.

    No related PR addressing this unification was found. The technical debt described remains outstanding on master.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions