DocumentValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 19
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateAttribute() 0 7 2
1
<?php
2
3
/**
4
 * @link https://github.com/yiibr/yii2-br-validator
5
 * @license https://github.com/yiibr/yii2-br-validator/blob/master/LICENSE
6
 */
7
8
namespace yiibr\brvalidator;
9
10
use yii\validators\Validator;
11
12
class DocumentValidator extends Validator {
13
14
    /**
15
     * @var bool whether the attribute value can removed non digits characteres. Defaults to false.
16
     */
17
    public $digitsOnly = false;
18
19
    /**
20
     * @inheritdoc
21
     */
22 1
    public function validateAttribute($model, $attribute)
23
    {
24 1
        if ($this->digitsOnly) {
25 1
            $model->$attribute = preg_replace('/\D+/', '', $model->$attribute);
26
        }
27 1
        parent::validateAttribute($model, $attribute);
28 1
    }
29
30
}
31