Action::fire()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.2222
c 0
b 0
f 0
cc 6
nc 6
nop 2
crap 6
1
<?php
2
3
namespace EventyClassic;
4
5
class Action extends Event
6
{
7
    /**
8
     * Runs an action.
9
     *
10
     * When an action is fired, all listeners are run in the order supplied when adding them.
11
     *
12
     * @param  string $action Name of action.
13
     * @param  array  $args   Arguments passed to the filter.
14
     *
15
     * @return void
16
     */
17 5
    public function fire($action, $args)
18
    {
19 5
        if ($this->getListeners()) {
20 5
            $listeners = $this->getListeners();
21
22 5
            foreach ($listeners as $listener) {
23 5
                if ($listener['hook'] == $action) {
24 5
                    $parameters = [];
25
26 5
                    for ($i = 0; $i < $listener['arguments']; $i++) {
27 5
                        if (isset($args[$i])) {
28 1
                            $parameters[] = $args[$i];
29
                        }
30
                    }
31
32 5
                    call_user_func_array($this->getFunction($listener['callback']), $parameters);
33
                }
34
            }
35
        }
36 4
    }
37
}
38