ActiveField::init()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 14
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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