/** * Source currency * @param $source * * Destination currency * @param $destination * * Amount to convert * @param $amount */ function convert($source, $destination, $amount) { $currencies = $this->source->fetch(); if (!isset($currencies[$source])) { throw new \RuntimeException("Currency not found: {$source}"); } if (!isset($currencies[$destination])) { throw new \RuntimeException("Currency not found: {$destination}"); } return $amount * $currencies[$destination] / $currencies[$source]; }
/** * Generates, executes SQL query and fetches the single row. * @return Entity|FALSE array on success, FALSE if no next record */ public function fetch() { $this->buildQuery(); return $this->dataSource->fetch(); }
function render() { return view('converter::index', ['endpoint' => config('currency.api_uri'), 'values' => $this->source->fetch()]); }