Completed
Pull Request — master (#44)
by Hiraku
02:30
created

JoinPoint::detachAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/*
3
 * hirak/prestissimo
4
 * @author Hiraku NAKANO
5
 * @license MIT https://github.com/hirak/prestissimo
6
 */
7
namespace Hirak\Prestissimo\Aspects;
8
9
use SplSubject;
10
use SplObserver;
11
use SplObjectStorage;
12
13
/**
14
 * Simple EventDispatcher for extending downloader
15
 */
16
class JoinPoint implements SplSubject
17
{
18
    /** @var SplObjectStorage */
19
    protected $storage;
20
21
    /** @var HttpGetRequest */
22
    protected $request;
23
24
    /** @var HttpGetResponse */
25
    protected $response;
26
27
    /** @var string */
28
    protected $name;
29
30
    /**
31
     * @param string $pointName
32
     */
33 19
    public function __construct($pointName, HttpGetRequest $request)
34
    {
35 19
        $this->name = $pointName;
36 19
        $this->detachAll();
37 19
        $this->request = $request;
38 19
    }
39
40 8
    public function attach(SplObserver $observer)
41
    {
42 8
        $this->storage->attach($observer);
43 8
    }
44
45 1
    public function detach(SplObserver $observer)
46
    {
47 1
        $this->storage->detach($observer);
48 1
    }
49
50 19
    public function detachAll()
51
    {
52 19
        $this->storage = new SplObjectStorage;
53 19
    }
54
55 6
    public function notify()
56
    {
57 6
        foreach ($this->storage as $observer) {
58 6
            $observer->update($this);
59 6
        }
60 6
    }
61
62 14
    final public function refRequest()
63
    {
64 14
        return $this->request;
65
    }
66
67 1
    public function setRequest(HttpGetRequest $req)
68
    {
69 1
        $this->request = $req;
70 1
    }
71
72 7
    final public function refResponse()
73
    {
74 7
        return $this->response;
75
    }
76
77 7
    public function setResponse(HttpGetResponse $res)
78
    {
79 7
        $this->response = $res;
80 7
    }
81
82 16
    public function __toString()
83
    {
84 16
        return $this->name;
85
    }
86
}
87