RateType::getParent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/*
3
 * This file is part of the Exchange Rate Bundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\ExchangeRate\Form\Type;
11
12
use RunOpenCode\ExchangeRate\Configuration;
13
use RunOpenCode\ExchangeRate\Contract\RatesConfigurationRegistryInterface;
14
use Symfony\Component\Form\AbstractType;
15
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
16
use Symfony\Component\OptionsResolver\OptionsResolver;
17
18
/**
19
 * Class RateType
20
 *
21
 * Rate choice type - which can be used for CRUD operations only.
22
 *
23
 * @package RunOpenCode\Bundle\ExchangeRate\Form\Type
24
 */
25
class RateType extends AbstractType
26
{
27
    /**
28
     * @var array
29
     */
30
    protected $defaults;
31
32 11
    public function __construct(RatesConfigurationRegistryInterface $registry, array $defaults = [])
33
    {
34 11
        $choices = [];
35
36
        /**
37
         * @var Configuration $configuration
38
         */
39 11
        foreach ($registry as $configuration) {
40 11
            $choice = sprintf('%s.%s.%s', $configuration->getSourceName(), $configuration->getRateType(), $configuration->getCurrencyCode());
41 11
            $choices[$choice] = $choice;
42
        }
43
44 11
        $this->defaults = array_merge(array(
45 11
            'choice_translation_domain' => 'runopencode_exchange_rate',
46 11
            'choices' => $choices
47 11
        ), $defaults);
48 11
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 10
    public function configureOptions(OptionsResolver $resolver)
54
    {
55
        $resolver
56 10
            ->setDefaults($this->defaults);
57 10
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 10
    public function getParent()
63
    {
64 10
        return ChoiceType::class;
65
    }
66
}
67