Example #1
0
 /**
  * @param string $sourceCode
  * @param string $targetCode
  *
  * @return ExchangeRateInterface
  */
 private function getExchangeRate($sourceCode, $targetCode)
 {
     $sourceTargetIndex = $this->createIndex($sourceCode, $targetCode);
     if (isset($this->cache[$sourceTargetIndex])) {
         return $this->cache[$sourceTargetIndex];
     }
     $targetSourceIndex = $this->createIndex($targetCode, $sourceCode);
     if (isset($this->cache[$targetSourceIndex])) {
         return $this->cache[$targetSourceIndex];
     }
     return $this->cache[$sourceTargetIndex] = $this->exchangeRateRepository->findOneWithCurrencyPair($sourceCode, $targetCode);
 }
Example #2
0
 /**
  * @param ExchangeRateInterface $exchangeRate
  */
 private function saveExchangeRate(ExchangeRateInterface $exchangeRate)
 {
     $this->exchangeRateRepository->add($exchangeRate);
     $this->sharedStorage->set('exchange_rate', $exchangeRate);
 }
 function it_return_given_value_if_both_currencie_in_currency_pair_are_the_same(ExchangeRateRepositoryInterface $exchangeRateRepository)
 {
     $exchangeRateRepository->findOneWithCurrencyPair('GBP', 'GBP')->willReturn(null);
     $this->convert(666, 'GBP', 'GBP')->shouldReturn(666);
 }
 /**
  * @param CurrencyInterface $baseCurrency
  * @param CurrencyInterface $targetCurrency
  *
  * @return bool
  */
 private function isCurrencyPairUnique(CurrencyInterface $baseCurrency, CurrencyInterface $targetCurrency)
 {
     $exchangeRate = $this->exchangeRateRepository->findOneWithCurrencyPair($baseCurrency->getCode(), $targetCurrency->getCode());
     return null === $exchangeRate;
 }