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

DocumentValidator::validateAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 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