ActiveField::widget()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
/**
4
 * @author Anton Tuyakhov <[email protected]>
5
 */
6
7
namespace tuyakhov\braintree;
8
9
use yii\helpers\Inflector;
10
11
class ActiveField extends \yii\bootstrap\ActiveField
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function init()
17
    {
18
        parent::init();
19
20
        $inputName = explode('_', $this->attribute);
21
        if (count($inputName) > 1) {
22
            $inputName[0] = $inputName[1];
23
        }
24
        $this->inputOptions = array_merge(
25
            [
26
                'data-braintree-name' => Inflector::underscore($inputName[0]),
27
                'autocomplete' => 'off',
28
            ],
29
            $this->inputOptions
30
        );
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function widget($class, $config = [])
37
    {
38
        $config = array_merge(['options' => $this->inputOptions], $config);
39
40
        return parent::widget($class, $config);
41
    }
42
}
43