MultiFilter::setFilters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace betadog\yii1;
4
5
/**
6
 * Usage:
7
 *
8
 * ['name', 'betadog\\yii1\\MultiFilter', 'filters' => ['trim', 'strtolower',]],
9
 *
10
 */
11
class MultiFilter extends \CValidator
12
{
13
    /** @var array */
14
    protected $filters;
15
16
    public function setFilters($value)
17
    {
18
        $this->filters = (array)$value;
19
    }
20
21
    protected function validateAttribute($object, $attribute)
22
    {
23
        foreach ($this->filters as $filter) {
24
            if (!is_callable($filter)) {
25
                throw new \CException(\Yii::t('yii', 'The "filter" property must be specified with a valid callback.'));
26
            }
27
28
            $object->$attribute = call_user_func_array($filter, [$object->$attribute]);
29
        }
30
    }
31
}