CountryDropdownField::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 3
eloc 6
c 2
b 0
f 2
nc 4
nop 4
dl 0
loc 10
rs 10
1
<?php
2
3
namespace LeKoala\GeoTools\Fields;
4
5
use ArrayAccess;
6
use LeKoala\GeoTools\CountriesList;
7
use SilverStripe\Forms\DropdownField;
8
9
class CountryDropdownField extends DropdownField
10
{
11
    /**
12
     * @var bool
13
     */
14
    protected $hasEmptyDefault = true;
15
16
    /**
17
     * @param string $name
18
     * @param string$title
19
     * @param array<string,string>|ArrayAccess<string,string> $source
20
     * @param mixed $value
21
     */
22
    public function __construct($name = 'CountryCode', $title = null, $source = [], $value = null)
23
    {
24
        if ($title === null) {
25
            $title = _t('CountryDropdownField.TITLE', 'Country');
26
        }
27
        if (empty($source)) {
28
            $source = CountriesList::get();
29
        }
30
        $this->setEmptyString(_t('CountryDropdownField.PLEASESELECTACOUNTRY', 'Please select a country'));
31
        parent::__construct($name, $title, $source, $value);
32
    }
33
}
34