From 43bee7bfe48c5c1b649bb1f7d2a9316ffa0a037b Mon Sep 17 00:00:00 2001 From: objec Date: Thu, 30 Apr 2026 14:21:34 +0400 Subject: [PATCH] Refactor save_customer method to saveCustomer for PSR compliance Signed-off-by: objec --- app/Controllers/Customers.php | 4 ++-- app/Models/Customer.php | 20 +++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/Controllers/Customers.php b/app/Controllers/Customers.php index f69d9a044..1b611db59 100644 --- a/app/Controllers/Customers.php +++ b/app/Controllers/Customers.php @@ -231,7 +231,7 @@ class Customers extends Persons 'sales_tax_code_id' => $this->request->getPost('sales_tax_code_id') == '' ? null : $this->request->getPost('sales_tax_code_id', FILTER_SANITIZE_NUMBER_INT) ]; - if ($this->customer->save_customer($personData, $customerData, $customerId)) { + if ($this->customer->saveCustomer($personData, $customerData, $customerId)) { Events::trigger('customer_saved', $customerData); // New customer @@ -400,7 +400,7 @@ class Customers extends Persons if ($invalidated) { $failCodes[] = $rowNumber; log_message('error', "Row $rowNumber was not imported: Either email or account number already exist or data was invalid."); - } elseif ($this->customer->save_customer($person_data, $customer_data)) { + } elseif ($this->customer->saveCustomer($person_data, $customer_data)) { Events::trigger('customer_saved', $person_data); } else { $failCodes[] = $rowNumber; diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 60f0c49e2..c894c19e8 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -210,28 +210,26 @@ class Customer extends Person /** * Inserts or updates a customer */ - public function save_customer(array &$person_data, array &$customer_data, int $customer_id = NEW_ENTRY): bool + public function saveCustomer(array &$personData, array &$customerData, int $customerId = NEW_ENTRY): bool { $success = false; $this->db->transStart(); - if (parent::save_value($person_data, $customer_id)) { + if (parent::save_value($personData, $customerId)) { $builder = $this->db->table('customers'); - if ($customer_id == NEW_ENTRY || !$customer_id || !$this->exists($customer_id)) { - $customer_data['person_id'] = $person_data['person_id']; - $success = $builder->insert($customer_data); + if ($customerId == NEW_ENTRY || !$customerId || !$this->exists($customerId)) { + $customerData['person_id'] = $personData['person_id']; + $success = $builder->insert($customerData); } else { - $builder->where('person_id', $customer_id); - $success = $builder->update($customer_data); - $customer_data['person_id'] = $customer_id; + $builder->where('person_id', $customerId); + $success = $builder->update($customerData); + $customerData['person_id'] = $customerId; } } $this->db->transComplete(); - $success &= $this->db->transStatus(); - - return $success; + return $success && $this->db->transStatus(); } /**