MultiFilter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 7
c 2
b 1
f 1
dl 0
loc 18
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setFilters() 0 3 1
A validateAttribute() 0 8 3
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
}