Completed
Pull Request — master (#32)
by Yann
03:35
created

EventDispatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Yokai\SecurityTokenBundle;
4
5
use DateTime;
6
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
7
use Yokai\SecurityTokenBundle\Entity\Token;
8
use Yokai\SecurityTokenBundle\Event\ConsumeTokenEvent;
9
use Yokai\SecurityTokenBundle\Event\CreateTokenEvent;
10
use Yokai\SecurityTokenBundle\Event\TokenAlreadyConsumedEvent;
11
use Yokai\SecurityTokenBundle\Event\TokenConsumedEvent;
12
use Yokai\SecurityTokenBundle\Event\TokenCreatedEvent;
13
use Yokai\SecurityTokenBundle\Event\TokenExpiredEvent;
14
use Yokai\SecurityTokenBundle\Event\TokenNotFoundEvent;
15
use Yokai\SecurityTokenBundle\Event\TokenRetrievedEvent;
16
use Yokai\SecurityTokenBundle\Event\TokenTotallyConsumedEvent;
17
18
/**
19
 * @author Yann Eugoné <[email protected]>
20
 */
21
class EventDispatcher
0 ignored issues
show
Complexity introduced by
The class EventDispatcher has a coupling between objects value of 23. Consider to reduce the number of dependencies under 13.
Loading history...
22
{
23
    /**
24
     * @var EventDispatcherInterface
25
     */
26
    private $eventDispatcher;
27
28
    /**
29
     * @param EventDispatcherInterface $eventDispatcher
30
     */
31
    public function __construct(EventDispatcherInterface $eventDispatcher)
32 7
    {
33
        $this->eventDispatcher = $eventDispatcher;
34 7
    }
35 7
36
    /**
37
     * @param string $purpose
38
     * @param string $value
39
     * @param array  $payload
40
     *
41
     * @return CreateTokenEvent
42
     */
43
    public function createToken($purpose, $value, array $payload)
44 1
    {
45
        $this->eventDispatcher->dispatch(
46 1
            TokenEvents::CREATE_TOKEN,
47 1
            $event = new CreateTokenEvent($purpose, $value, $payload)
48 1
        );
49
50
        return $event;
51 1
    }
52
53
    /**
54
     * @param Token $token
55
     *
56
     * @return TokenCreatedEvent
57
     */
58
    public function tokenCreated(Token $token)
59 1
    {
60
        $this->eventDispatcher->dispatch(
61 1
            TokenEvents::TOKEN_CREATED,
62 1
            $event = new TokenCreatedEvent($token)
63 1
        );
64
65
        return $event;
66 1
    }
67
68
    /**
69
     * @param Token         $token
70
     * @param DateTime|null $at
71
     * @param array         $information
72
     *
73
     * @return ConsumeTokenEvent
74
     */
75
    public function consumeToken(Token $token, DateTime $at = null, array $information = [])
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $at. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
76 1
    {
77
        $this->eventDispatcher->dispatch(
78 1
            TokenEvents::CONSUME_TOKEN,
79 1
            $event = new ConsumeTokenEvent($token, $at, $information)
80 1
        );
81
82
        return $event;
83 1
    }
84
85
    /**
86
     * @param Token $token
87
     *
88
     * @return TokenConsumedEvent
89
     */
90
    public function tokenConsumed(Token $token)
91 1
    {
92
        $this->eventDispatcher->dispatch(
93 1
            TokenEvents::TOKEN_CONSUMED,
94 1
            $event = new TokenConsumedEvent($token)
95 1
        );
96
97
        return $event;
98 1
    }
99
100
    /**
101
     * @param Token $token
102
     *
103
     * @return TokenTotallyConsumedEvent
104
     */
105
    public function tokenTotallyConsumed(Token $token)
106 1
    {
107
        $this->eventDispatcher->dispatch(
108 1
            TokenEvents::TOKEN_TOTALLY_CONSUMED,
109 1
            $event = new TokenTotallyConsumedEvent($token)
110 1
        );
111
112
        return $event;
113 1
    }
114
115
    /**
116
     * @param string $purpose
117
     * @param string $value
118
     *
119
     * @return TokenNotFoundEvent
120
     */
121
    public function tokenNotFound($purpose, $value)
122 1
    {
123
        $this->eventDispatcher->dispatch(
124 1
            TokenEvents::TOKEN_NOT_FOUND,
125 1
            $event = new TokenNotFoundEvent($purpose, $value)
126 1
        );
127
128
        return $event;
129 1
    }
130
131
    /**
132
     * @param string $purpose
133
     * @param string $value
134
     *
135
     * @return TokenExpiredEvent
136
     */
137
    public function tokenExpired($purpose, $value)
138 1
    {
139
        $this->eventDispatcher->dispatch(
140 1
            TokenEvents::TOKEN_EXPIRED,
141 1
            $event = new TokenExpiredEvent($purpose, $value)
142 1
        );
143
144
        return $event;
145 1
    }
146
147
    /**
148
     * @param string $purpose
149
     * @param string $value
150
     *
151
     * @return TokenAlreadyConsumedEvent
152
     */
153
    public function tokenAlreadyConsumed($purpose, $value)
154
    {
155
        $this->eventDispatcher->dispatch(
156
            TokenEvents::TOKEN_ALREADY_CONSUMED,
157
            $event = new TokenAlreadyConsumedEvent($purpose, $value)
158
        );
159
160
        return $event;
161
    }
162
163
    /**
164
     * @param Token $token
165
     *
166
     * @return TokenRetrievedEvent
167
     */
168
    public function tokenRetrieved(Token $token)
169
    {
170 1
        $this->eventDispatcher->dispatch(
171
            TokenEvents::TOKEN_RETRIEVED,
172 1
            $event = new TokenRetrievedEvent($token)
173 1
        );
174 1
175
        return $event;
176
    }
177
}
178