Completed
Push — master ( db026b...56b106 )
by Oliver
04:09 queued 02:28
created

Composite::detach()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Metabor\Callback;
4
5
use MetaborStd\CallbackInterface;
6
7
/**
8
 * @author Oliver Tischlinger
9
 */
10
class Composite implements CallbackInterface, \Countable, \IteratorAggregate
11
{
12
    /**
13
     * @var \SplObjectStorage
14
     */
15
    private $callbacks;
16
17
    /**
18
     *
19
     */
20 1
    public function __construct()
21
    {
22 1
        $this->callbacks = new \SplObjectStorage();
23 1
    }
24
25
    /**
26
     * @see MetaborStd.CallbackInterface::__invoke()
27
     */
28 1
    public function __invoke()
29
    {
30 1
        $args = func_get_args();
31
        /* @var $callback callable */
32 1
        foreach ($this->callbacks as $callback) {
33 1
            if (empty($args)) {
34
                $callback();
35
            } else {
36 1
                call_user_func_array($callback, $args);
37
            }
38 1
        }
39 1
    }
40
41
    /**
42
     * @param CallbackInterface $callback
43
     */
44 1
    public function attach(CallbackInterface $callback)
45
    {
46 1
        $this->callbacks->attach($callback);
47 1
    }
48
49
    /**
50
     * @param CallbackInterface $callback
51
     */
52 1
    public function detach(CallbackInterface $callback)
53
    {
54 1
        $this->callbacks->detach($callback);
55 1
    }
56
57
    /**
58
     * @return \Iterator
59
     */
60
    public function getIterator()
61
    {
62
        return $this->callbacks;
63
    }
64
65
    /**
66
     * @return int
67
     */
68
    public function count()
69
    {
70
        return $this->callbacks->count();
71
    }
72
}
73