From 843a476d0bf46c7eb0cfb1fa489ac360a5021b7b Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Sat, 5 Dec 2020 11:43:38 +0200 Subject: [PATCH] The get_value method check the existence of a property with array_key_exists --- application/models/Admins_model.php | 10 ++++++---- application/models/Appointments_model.php | 6 +++--- application/models/Customers_model.php | 6 +++--- application/models/Providers_model.php | 10 +++++----- application/models/Secretaries_model.php | 14 ++++++++------ application/models/Services_model.php | 9 +++++---- 6 files changed, 30 insertions(+), 25 deletions(-) diff --git a/application/models/Admins_model.php b/application/models/Admins_model.php index 74e19531..98bf91fe 100644 --- a/application/models/Admins_model.php +++ b/application/models/Admins_model.php @@ -404,21 +404,23 @@ class Admins_model extends EA_Model { // Check whether the admin record exists. $result = $this->db->get_where('users', ['id' => $admin_id]); - if ($result->num_rows() == 0) + + if ($result->num_rows() === 0) { throw new Exception('The record with the given id does not exist in the ' . 'database: ' . $admin_id); } // Check if the required field name exist in database. - $provider = $result->row_array(); - if ( ! isset($provider[$field_name])) + $row_data = $result->row_array(); + + if ( ! array_key_exists($field_name, $row_data)) { throw new Exception('The given $field_name argument does not exist in the ' . 'database: ' . $field_name); } - return $provider[$field_name]; + return $row_data[$field_name]; } /** diff --git a/application/models/Appointments_model.php b/application/models/Appointments_model.php index f4b89c72..bb472bd7 100644 --- a/application/models/Appointments_model.php +++ b/application/models/Appointments_model.php @@ -352,13 +352,13 @@ class Appointments_model extends EA_Model { if ($this->db->get_where('appointments', ['id' => $appointment_id])->num_rows() == 0) { - throw new Exception('The record with the provided id ' - . 'does not exist in the database: ' . $appointment_id); + throw new Exception('The record with the provided ID does not exist in the database: ' + . $appointment_id); } $row_data = $this->db->get_where('appointments', ['id' => $appointment_id])->row_array(); - if ( ! isset($row_data[$field_name])) + if ( ! array_key_exists($field_name, $row_data)) { throw new Exception('The given field name does not exist in the database: ' . $field_name); } diff --git a/application/models/Customers_model.php b/application/models/Customers_model.php index 7a82bee8..0104fa7b 100644 --- a/application/models/Customers_model.php +++ b/application/models/Customers_model.php @@ -331,10 +331,10 @@ class Customers_model extends EA_Model { $row_data = $this->db->get_where('users', ['id' => $customer_id])->row_array(); - if ( ! isset($row_data[$field_name])) + if ( ! array_key_exists($field_name, $row_data)) { - throw new Exception('The given $field_name argument does not' - . 'exist in the database: ' . $field_name); + throw new Exception('The given $field_name argument does not exist in the database: ' + . $field_name); } $customer = $this->db->get_where('users', ['id' => $customer_id])->row_array(); diff --git a/application/models/Providers_model.php b/application/models/Providers_model.php index 59feae2a..bf708bef 100755 --- a/application/models/Providers_model.php +++ b/application/models/Providers_model.php @@ -493,18 +493,18 @@ class Providers_model extends EA_Model { if ($result->num_rows() == 0) { - throw new Exception('The record with the $provider_id argument does not exist in ' - . 'the database: ' . $provider_id); + throw new Exception('The record with the $provider_id argument does not exist in the database: ' + . $provider_id); } - $provider = $result->row_array(); + $row_data = $result->row_array(); - if ( ! isset($provider[$field_name])) + if ( ! isset($row_data[$field_name])) { throw new Exception('The given $field_name argument does not exist in the database: ' . $field_name); } - return $provider[$field_name]; + return $row_data[$field_name]; } /** diff --git a/application/models/Secretaries_model.php b/application/models/Secretaries_model.php index cb7aa038..6802923d 100644 --- a/application/models/Secretaries_model.php +++ b/application/models/Secretaries_model.php @@ -480,21 +480,23 @@ class Secretaries_model extends EA_Model { // Check whether the secretary record exists. $result = $this->db->get_where('users', ['id' => $secretary_id]); - if ($result->num_rows() == 0) + + if ($result->num_rows() === 0) { throw new Exception('The record with the given id does not exist in the ' . 'database: ' . $secretary_id); } // Check if the required field name exist in database. - $provider = $result->row_array(); - if ( ! isset($provider[$field_name])) + $row_data = $result->row_array(); + + if ( ! array_key_exists($field_name, $row_data)) { - throw new Exception('The given $field_name argument does not exist in the ' - . 'database: ' . $field_name); + throw new Exception('The given $field_name argument does not exist in the database: ' + . $field_name); } - return $provider[$field_name]; + return $row_data[$field_name]; } /** diff --git a/application/models/Services_model.php b/application/models/Services_model.php index 02cf5d97..eceb05fe 100644 --- a/application/models/Services_model.php +++ b/application/models/Services_model.php @@ -303,13 +303,14 @@ class Services_model extends EA_Model { } $row_data = $this->db->get_where('services', ['id' => $service_id])->row_array(); - if ( ! isset($row_data[$field_name])) + + if ( ! array_key_exists($field_name, $row_data)) { - throw new Exception('The given $field_name argument does not exist in the database: ' . $field_name); + throw new Exception('The given $field_name argument does not exist in the database: ' + . $field_name); } - $setting = $this->db->get_where('services', ['id' => $service_id])->row_array(); - return $setting[$field_name]; + return $row_data[$field_name]; } /**