Completed
Push — master ( 0916fa...5a50ca )
by Michał
17s
created

OrderExchangeRateAndCurrencyUpdater::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Core\Updater;
13
14
use Sylius\Component\Core\Model\OrderInterface;
15
use Sylius\Component\Currency\Context\CurrencyContextInterface;
16
use Sylius\Component\Currency\Model\CurrencyInterface;
17
use Sylius\Component\Resource\Repository\RepositoryInterface;
18
19
/**
20
 * @author Anna Walasek <[email protected]>
21
 */
22
final class OrderExchangeRateAndCurrencyUpdater implements OrderUpdaterInterface
23
{
24
    /**
25
     * @var CurrencyContextInterface
26
     */
27
    private $currencyContext;
28
29
    /**
30
     * @var RepositoryInterface
31
     */
32
    private $currencyRepository;
33
34
    /**
35
     * @param CurrencyContextInterface $currencyContext
36
     * @param RepositoryInterface $currencyRepository
37
     */
38
    public function __construct(CurrencyContextInterface $currencyContext, RepositoryInterface $currencyRepository)
39
    {
40
        $this->currencyContext = $currencyContext;
41
        $this->currencyRepository = $currencyRepository;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function update(OrderInterface $order)
48
    {
49
        /** @var CurrencyInterface $currency */
50
        $currency = $this->currencyRepository->findOneBy(['code' => $this->currencyContext->getCurrencyCode()]);
51
52
        $order->setCurrencyCode($currency->getCode());
53
        $order->setExchangeRate($currency->getExchangeRate());
54
    }
55
}
56