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

OrderExchangeRateUpdater::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
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\Model\CurrencyInterface;
16
use Sylius\Component\Resource\Repository\RepositoryInterface;
17
use Webmozart\Assert\Assert;
18
19
/**
20
 * @author Jan Góralski <[email protected]>
21
 */
22
final class OrderExchangeRateUpdater implements OrderUpdaterInterface
23
{
24
    /**
25
     * @var RepositoryInterface
26
     */
27
    private $currencyRepository;
28
29
    /**
30
     * @param RepositoryInterface $currencyRepository
31
     */
32
    public function __construct(RepositoryInterface $currencyRepository)
33
    {
34
        $this->currencyRepository = $currencyRepository;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function update(OrderInterface $order)
41
    {
42
        $currencyCode = $order->getCurrencyCode();
43
        /** @var CurrencyInterface $currency */
44
        $currency = $this->currencyRepository->findOneBy(['code' => $currencyCode]);
45
46
        Assert::notNull($currency);
47
48
        $order->setExchangeRate($currency->getExchangeRate());
49
    }
50
}
51