Completed
Push — master ( 60e110...b5c1bd )
by Leandro
05:00
created

DocumentValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 19
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
    public function validateAttribute($model, $attribute)
23
    {
24
        if ($this->digitsOnly) {
25
            $model->$attribute = preg_replace('/\D+/', '', $model->$attribute);
26
        }
27
        parent::validateAttribute($model, $attribute);
28
    }
29
30
}
31