From d8beedf1f7f722939b49bc7f9874018aa2e5adc7 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Fri, 1 Jul 2016 19:12:48 +0100 Subject: [PATCH] Small code optimisation: review for loops (#709) --- application/controllers/Items.php | 9 +++++---- application/controllers/Reports.php | 2 +- application/controllers/Sales.php | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 9e8037980..361886bfc 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -367,7 +367,8 @@ class Items extends Secure_Controller $items_taxes_data = array(); $tax_names = $this->input->post('tax_names'); $tax_percents = $this->input->post('tax_percents'); - for($k = 0; $k < count($tax_percents); ++$k) + $count = count($tax_percents); + for ($k = 0; $k < $count; ++$k) { if(is_numeric($tax_percents[$k])) { @@ -520,8 +521,8 @@ class Items extends Secure_Controller $tax_names = $this->input->post('tax_names'); $tax_percents = $this->input->post('tax_percents'); $tax_updated = FALSE; - - for($k = 0; $k < count($tax_percents); ++$k) + $count = count($tax_percents); + for ($k = 0; $k < $count; ++$k) { if(!empty($tax_names[$k]) && is_numeric($tax_percents[$k])) { @@ -658,7 +659,7 @@ class Items extends Secure_Controller // array to store information if location got a quantity $allowed_locations = $this->Stock_location->get_allowed_locations(); - for($col = 24; $col < $cols; $col = $col + 2) + for ($col = 24; $col < $cols; $col = $col + 2) { $location_id = $data[$col]; if(array_key_exists($location_id, $allowed_locations)) diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index be848d996..c23a1b6ae 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -740,7 +740,7 @@ class Reports extends Secure_Controller $data['specific_input_name'] = $this->lang->line('reports_discount'); $discounts = array(); - for($i = 0; $i <= 100; $i += 10) + for ($i = 0; $i <= 100; $i += 10) { $discounts[$i] = $i . '%'; } diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 6a613b673..4dcbbe45a 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -752,7 +752,8 @@ class Sales extends Secure_Controller // go through all the payment type input from the form, make sure the form matches the name and iterator number $payments = array(); - for($i = 0; $i < $this->input->post('number_of_payments'); ++$i) + $number_of_payments = $this->input->post('number_of_payments'); + for ($i = 0; $i < $number_of_payments; ++$i) { $payment_amount = $this->input->post('payment_amount_' . $i); $payment_type = $this->input->post('payment_type_' . $i);