Filter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 14
c 1
b 0
f 0
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B fire() 0 24 7
1
<?php
2
3
namespace EventyClassic;
4
5
class Filter extends Event
6
{
7
    /**
8
     * Holds the value of the filter.
9
     *
10
     * @var mixed
11
     */
12
    protected $value;
13
14
    /**
15
     * Filters a value.
16
     *
17
     * When a filter is fired, all listeners are run in the order supplied when adding them.
18
     *
19
     * @param  string $action Name of filter.
20
     * @param  array  $args   Arguments passed to the filter.
21
     *
22
     * @return string         Always returns the value.
23
     */
24 4
    public function fire($action, $args)
25
    {
26 4
        $this->value = isset($args[0]) ? $args[0] : '';
27
28 4
        if ($this->getListeners()) {
29 4
            $listeners = $this->getListeners();
30
31 4
            foreach ($listeners as $listener) {
32 4
                if ($listener['hook'] == $action) {
33 4
                    $parameters = [];
34 4
                    $args[0] = $this->value;
35
36 4
                    for ($i = 0; $i < $listener['arguments']; $i++) {
37 4
                        if (isset($args[$i])) {
38 4
                            $parameters[] = $args[$i];
39
                        }
40
                    }
41
42 4
                    $this->value = call_user_func_array($this->getFunction($listener['callback']), $parameters);
43
                }
44
            }
45
        }
46
47 3
        return $this->value;
48
    }
49
}
50