IconPicker   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 8 2
A registerClientScript() 0 9 1
1
<?php
2
3
namespace dominus77\iconpicker;
4
5
use yii\helpers\Html;
6
use yii\helpers\Json;
7
use yii\widgets\InputWidget;
8
9
/**
10
 * Class IconPicker
11
 * @package dominus77\iconpicker
12
 */
13
class IconPicker extends InputWidget
14
{
15
    /**
16
     * Options plugin
17
     * @var array
18
     * @see https://farbelous.github.io/fontawesome-iconpicker/
19
     */
20
    public $clientOptions = [];
21
22
    /**
23
     * @inheritdoc
24
     */
25 6
    public function run()
26
    {
27 6
        if ($this->hasModel()) {
28 3
            echo Html::activeTextInput($this->model, $this->attribute, $this->options);
29
        } else {
30 3
            echo Html::textInput($this->name, $this->value, $this->options);
31
        }
32 6
        $this->registerClientScript();
33 6
    }
34
35
    /**
36
     * Publish resource
37
     */
38 6
    protected function registerClientScript()
39
    {
40 6
        $js = [];
41 6
        $view = $this->getView();
42 6
        IconPickerAsset::register($view);
43 6
        $id = $this->options['id'];
44 6
        $options = Json::encode($this->clientOptions);
45 6
        $js[] = "$('#{$id}').iconpicker($options);";
46 6
        $view->registerJs(implode("\n", $js));
47 6
    }
48
}
49