StaticCombo   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 36
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPluginOptions() 0 7 1
A getCurrentOptions() 0 10 3
1
<?php
2
/**
3
 * Combo widget for Yii2
4
 *
5
 * @link      https://github.com/hiqdev/yii2-combo
6
 * @package   yii2-combo
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\combo;
12
13
/**
14
 * Class for Static combo.
15
 *
16
 * @property mixed data
17
 */
18
class StaticCombo extends Combo
19
{
20
    public $name = 'default';
21
22
    public $type = 'default';
23
24
    public $data = [];
25
26
    /**
27
     * @var bool whether to add an empty option for the select. Works only when [[multiple]] is set to `false`.
28
     *
29
     * Info: The `select` HTML element selects the first option in the list,
30
     * if there is no other option marked as `selected`. This property prevents
31
     * this behaviour by adding option with empty value.
32
     */
33
    public $prependEmptyOption = true;
34
35
    public function getPluginOptions($options = [])
36
    {
37
        $options = parent::getPluginOptions();
38
        unset($options['select2Options']['ajax']);
39
40
        return $options;
41
    }
42
43
    protected function getCurrentOptions()
44
    {
45
        $option = [];
46
47
        if (!$this->multiple && $this->prependEmptyOption === true) {
48
            $option = ['' => ''];
49
        }
50
51
        return $option + (array) $this->data;
52
    }
53
}
54