
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.