Subject::attach()   A
last analyzed

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\Observer;
4
5
/**
6
 * @author Oliver Tischlinger
7
 */
8
class Subject implements \SplSubject
9
{
10
    /**
11
     * @var \SplObjectStorage
12
     */
13
    private $observers;
14
15
    /**
16
     */
17 27
    public function __construct()
18
    {
19 27
        $this->observers = new \SplObjectStorage();
20 27
    }
21
22
    /**
23
     * @see \SplSubject::attach()
24
     */
25 13
    public function attach(\SplObserver $observer)
26
    {
27 13
        $this->observers->attach($observer);
28 13
    }
29
30
    /**
31
     * @see \SplSubject::detach()
32
     */
33 2
    public function detach(\SplObserver $observer)
34
    {
35 2
        $this->observers->detach($observer);
36 2
    }
37
38
    /**
39
     * @see \SplSubject::notify()
40
     */
41 11
    public function notify()
42
    {
43
        /* @var $observer \SplObserver */
44 11
        foreach ($this->observers as $observer) {
45 9
            $observer->update($this);
46 7
        }
47 7
    }
48
49
    /**
50
     * @return \Traversable
51
     */
52 5
    public function getObservers()
53
    {
54 5
        return $this->observers;
55
    }
56
}
57