ExchangeEnquiryType::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace App\Form\Type;
6
7
use App\Entity\ExchangeEnquiry;
8
use App\ExchangeRates\ExchangeService;
9
use Symfony\Component\Form\AbstractType;
10
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
11
use Symfony\Component\Form\Extension\Core\Type\NumberType;
12
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
13
use Symfony\Component\Form\FormBuilderInterface;
14
use Symfony\Component\OptionsResolver\OptionsResolver;
15
16
class ExchangeEnquiryType extends AbstractType
17
{
18
    /**
19
     * @var ExchangeService
20
     */
21
    private $exchangeService;
22
23
    /**
24
     * ExchangeEnquiryType constructor.
25
     *
26
     * @param ExchangeService $exchangeService
27
     */
28
    public function __construct(ExchangeService $exchangeService)
29
    {
30
        $this->exchangeService = $exchangeService;
31
    }
32
33
    /**
34
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
35
     *
36
     * @param FormBuilderInterface $builder
37
     * @param array                $options
38
     */
39
    public function buildForm(FormBuilderInterface $builder, array $options)
40
    {
41
        $currencies = $this->exchangeService->getSupportedCurrencies();
42
        array_unshift($currencies, 'EUR');
43
        $currenciesList = array_combine($currencies, $currencies);
44
45
        $builder
46
            ->add(
47
                'baseCurrency',
48
                CurrencyType::class,
49
                [
50
                    'choice_loader' => null,
51
                    'choices'       => $currenciesList,
52
                ]
53
            )
54
            ->add('amount', NumberType::class)
55
            ->add(
56
                'targetCurrency',
57
                CurrencyType::class,
58
                [
59
                    'choice_loader' => null,
60
                    'choices'       => $currenciesList,
61
                ]
62
            )
63
            ->add('Exchange!', SubmitType::class);
64
    }
65
66
    /**
67
     * @param OptionsResolver $resolver
68
     */
69
    public function configureOptions(OptionsResolver $resolver)
70
    {
71
        $resolver->setDefaults([
72
            'data_class' => ExchangeEnquiry::class,
73
        ]);
74
    }
75
}
76