Completed
Push — master ( 61b824...9bd84d )
by Aleksandr
04:57
created

ActiveFieldTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 25
c 1
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 10 4
A __toString() 0 11 4
1
<?php
2
3
4
namespace carono\checksum;
5
6
use yii\helpers\Html;
7
8
/**
9
 * Trait ActiveFieldTrait
10
 *
11
 * @package carono\checksum
12
 * @mixin \yii\widgets\ActiveField
13
 */
14
trait ActiveFieldTrait
15
{
16
    public function init()
17
    {
18
        if (\Yii::$app->request instanceof Request && \Yii::$app->request->checksumIsEnabled()) {
19
            if (!$this->form->canGetProperty('_checksumInit')) {
20
                $this->form->attachBehavior('caronoChecksumBehavior', ActiveFormBehavior::className());
0 ignored issues
show
Bug introduced by
The property form does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
21
                \Yii::$app->request->clearStack($this->form->id);
22
            }
23
        }
24
        parent::init();
25
    }
26
27
    public function __toString()
28
    {
29
        $string = parent::__toString();
30
        if (\Yii::$app->request instanceof Request && \Yii::$app->request->checksumIsEnabled()) {
31
            if (preg_match('#<input|<select|<textarea#', $string)) {
32
                $attribute = Html::getAttributeName($this->attribute);
0 ignored issues
show
Bug introduced by
The property attribute does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
                \Yii::$app->request->stackField($this->form->id, $this->model->formName(), $attribute);
0 ignored issues
show
Bug introduced by
The property model does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
            }
35
        }
36
        return $string;
37
    }
38
}