Conditions | 6 |
Paths | 7 |
Total Lines | 30 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
21 | protected function updateOrCreate(array $managedCurrencies, $code, $rate) |
||
22 | { |
||
23 | if (!empty($managedCurrencies)) { |
||
24 | foreach ($managedCurrencies as $currency) { |
||
25 | if ($currency->getCode() !== $this->baseCurrency) { |
||
26 | $currency->setDefault(false); |
||
27 | } else { |
||
28 | $currency->setDefault(true); |
||
29 | } |
||
30 | |||
31 | if ($code === $currency->getCode()) { |
||
32 | $currency->setExchangeRate($rate); |
||
33 | $currency->setUpdatedAt(new \DateTime()); |
||
34 | |||
35 | return; |
||
36 | } |
||
37 | } |
||
38 | } else { |
||
39 | /** @var $currency CurrencyInterface */ |
||
40 | $currency = $this->repository->createNew(); |
||
41 | $currency->setCode($code); |
||
42 | $currency->setExchangeRate($rate); |
||
43 | if ($currency->getCode() === $this->baseCurrency) { |
||
44 | $currency->setDefault(true); |
||
45 | $currency->setIsActive(true); |
||
46 | } |
||
47 | |||
48 | $this->manager->persist($currency); |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 |