public function __construct(ICurrency $currency, ICurrencyRateProvider $provider, \DateTime $date = null)
 {
     $this->currency = $currency;
     $this->date = $date;
     $this->provider = $provider;
     $this->message = sprintf('Rate not found for currency %s and provider %s', $currency->getCode(), $provider->getName());
 }
 /**
  * {@inheritdoc}
  */
 public function getRate(ICurrency $currency, ICurrencyRateProvider $provider, \DateTime $rateDate = null)
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('r')->from($this->currencyRateClassName, 'r')->leftJoin('r.currency', 'c')->where($qb->expr()->eq('c.code', ':currency'))->andWhere($qb->expr()->eq('r.providerName', ':provider'))->setParameters(['currency' => $currency->getCode(), 'provider' => $provider->getName()])->orderBy('r.date', 'DESC');
     if (isset($rateDate)) {
         $qb->andWhere($qb->expr()->eq('r.date', ':date'))->setParameter('date', $rateDate->format('Y-m-d 00:00:00'));
     }
     $result = $qb->getQuery()->getResult();
     $result = reset($result);
     return $result;
 }
 /**
  * Get currency rate
  *
  * @param ICurrency $currency
  * @param ICurrencyRateProvider $provider
  * @param null $date
  * @return float
  */
 private function getRate(ICurrency $currency, ICurrencyRateProvider $provider, $date = null)
 {
     if ($currency->getCode() != $provider->getBaseCurrency()->getCode()) {
         $rate = $this->rateManager->getRate($currency, $provider, $date);
         if (!$rate) {
             return null;
         }
         if (!$provider->isInversed()) {
             $rate = $rate->getNominal() * $rate->getRate();
         } else {
             $rate = $rate->getNominal() / $rate->getRate();
         }
     } else {
         $rate = 1.0;
     }
     return $rate;
 }