DocumentValidator::validateAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 6
rs 10
1
<?php
2
3
namespace dynamikaweb\validators;
4
5
use yii\validators\Validator;
6
7
class DocumentValidator extends Validator {
8
9
    /**
10
     * @var bool whether the attribute value can removed non digits characteres. Defaults to false.
11
     */
12
    public $digitsOnly = false;
13
14
    /**
15
     * @inheritdoc
16
     */
17
    public function validateAttribute($model, $attribute)
18
    {
19
        if ($this->digitsOnly) {
20
            $model->$attribute = preg_replace('/\D+/', '', $model->$attribute);
21
        }
22
        parent::validateAttribute($model, $attribute);
23
    }
24
25
}
26