sfWidgetFormI18nSelect2ChoiceCurrency::configure()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 8.7624
cc 6
eloc 11
nc 8
nop 2
1
<?php
2
class sfWidgetFormI18nSelect2ChoiceCurrency extends sfWidgetFormSelect2Choice
3
{
4
    protected function configure($options = array(), $attributes = array())
5
    {
6
        parent::configure($options, $attributes);
7
8
        $this->addOption('culture', sfContext::getInstance()->getUser()->getCulture());
9
        $this->addOption('currencies');
10
        $this->addOption('add_empty', false);
11
12
        // populate choices with all currencies
13
        $culture = isset($options['culture']) ? $options['culture'] : 'en';
14
15
        $currencies = sfCultureInfo::getInstance($culture)->getCurrencies(isset($options['currencies']) ? $options['currencies'] : null);
16
17
        $addEmpty = isset($options['add_empty']) ? $options['add_empty'] : false;
18
        if (false !== $addEmpty)
19
        {
20
            $currencies = array_merge(array('' => true === $addEmpty ? '' : $addEmpty), $currencies);
21
        }
22
23
        $this->setOption('choices', $currencies);
24
    }
25
}