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

OrderExchangeRateUpdater   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A update() 0 10 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