Completed
Push — master ( b7e254...bcf326 )
by
unknown
09:07
created

ConvertPriceToAmount::convert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusMolliePlugin\Helper;
14
15
use Sylius\Bundle\MoneyBundle\Templating\Helper\FormatMoneyHelper;
16
use Sylius\Component\Currency\Context\CurrencyContextInterface;
17
use Sylius\Component\Locale\Context\LocaleContextInterface;
18
19
final class ConvertPriceToAmount
20
{
21
    /** @var CurrencyContextInterface */
22
    private $currencyContext;
23
24
    /** @var LocaleContextInterface */
25
    private $localeContext;
26
27
    /** @var FormatMoneyHelper */
28
    private $formatMoneyHelper;
29
30
    public function __construct(
31
        CurrencyContextInterface $currencyContext,
32
        LocaleContextInterface $localeContext,
33
        FormatMoneyHelper $formatMoneyHelper
34
    ) {
35
        $this->currencyContext = $currencyContext;
36
        $this->localeContext = $localeContext;
37
        $this->formatMoneyHelper = $formatMoneyHelper;
38
    }
39
40
    public function convert(int $price): string
41
    {
42
        return $this->formatMoneyHelper->formatAmount(
43
            $price,
44
            $this->currencyContext->getCurrencyCode(),
45
            $this->localeContext->getLocaleCode()
46
        );
47
    }
48
}
49