PHP Classes

Code updates to prevent unncessary calling of rate exchange API.

Recommend this page to a friend!

      Realtime PHP Currency Exchange  >  All threads  >  Code updates to prevent unncessary...  >  (Un) Subscribe thread alerts  
Subject:Code updates to prevent unncessary...
Summary:Code updates to prevent unncessary calling of rate exchange API.
Messages:2
Author:dharmang andhariya
Date:2014-05-13 06:19:52
 

  1. Code updates to prevent unncessary...   Reply   Report abuse  
Picture of dharmang andhariya dharmang andhariya - 2014-05-13 06:19:53
Hello,

I have a little concern over the following code, You are making call twice unnecessarily for the successful request.

public function convert($amount) {
$rate = 0.00;
$convertedAmount = FALSE;
if ($amount > 0) {
if ($this->openExchange()) {
$rate = $this->openExchange();
}
elseif ($this->currencyAPI()) {
$rate = $this->currencyAPI();
}
elseif ($this->yahooFinance()) {
$rate = $this->yahooFinance();
}

$convertedAmount = $this->calculateMoney($rate, $amount);
}
return $convertedAmount;
}


It could be corrected to following so only one request is required:


public function convert($amount) {
$rate = 0.00;
$convertedAmount = FALSE;
if ($amount > 0) {
$rateTmp = false;
if ($rateTmp = $this->openExchange()) {
$rate = $rateTmp;
}
elseif ($rateTmp = $this->currencyAPI()) {
$rate = $rateTmp;
}
elseif ($rateTmp = $this->yahooFinance()) {
$rate = $rateTmp;
}

$convertedAmount = $this->calculateMoney($rate, $amount);
}
return $convertedAmount;
}


let me know your views.

  2. Re: Code updates to prevent unncessary...   Reply   Report abuse  
Picture of Anish Karim C Anish Karim C - 2015-03-01 09:49:51 - In reply to message 1 from dharmang andhariya
Hi Dharmang,

Thank you for your advice. I have updated the script and will update the same here too.

Thank,
Anish.