DocumentValidator::validateAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 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