Completed
Pull Request — master (#32)
by Yann
01:30
created

EventDispatcher::createToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.9666
cc 1
nc 1
nop 3
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 7
    public function __construct(EventDispatcherInterface $eventDispatcher)
32
    {
33 7
        $this->eventDispatcher = $eventDispatcher;
34 7
    }
35
36
    /**
37
     * @param string $purpose
38
     * @param string $value
39
     * @param array  $payload
40
     *
41
     * @return CreateTokenEvent
42
     */
43 1
    public function createToken($purpose, $value, array $payload)
44
    {
45 1
        $this->eventDispatcher->dispatch(
46 1
            TokenEvents::CREATE_TOKEN,
47 1
            $event = new CreateTokenEvent($purpose, $value, $payload)
48
        );
49
50 1
        return $event;
51
    }
52
53
    /**
54
     * @param Token $token
55
     *
56
     * @return TokenCreatedEvent
57
     */
58 1
    public function tokenCreated(Token $token)
59
    {
60 1
        $this->eventDispatcher->dispatch(
61 1
            TokenEvents::TOKEN_CREATED,
62 1
            $event = new TokenCreatedEvent($token)
63
        );
64
65 1
        return $event;
66
    }
67
68
    /**
69
     * @param Token         $token
70
     * @param DateTime|null $at
71
     * @param array         $information
72
     *
73
     * @return ConsumeTokenEvent
74
     */
75 1
    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
    {
77 1
        $this->eventDispatcher->dispatch(
78 1
            TokenEvents::CONSUME_TOKEN,
79 1
            $event = new ConsumeTokenEvent($token, $at, $information)
80
        );
81
82 1
        return $event;
83
    }
84
85
    /**
86
     * @param Token $token
87
     *
88
     * @return TokenConsumedEvent
89
     */
90 1
    public function tokenConsumed(Token $token)
91
    {
92 1
        $this->eventDispatcher->dispatch(
93 1
            TokenEvents::TOKEN_CONSUMED,
94 1
            $event = new TokenConsumedEvent($token)
95
        );
96
97 1
        return $event;
98
    }
99
100
    /**
101
     * @param Token $token
102
     *
103
     * @return TokenTotallyConsumedEvent
104
     */
105 1
    public function tokenTotallyConsumed(Token $token)
106
    {
107 1
        $this->eventDispatcher->dispatch(
108 1
            TokenEvents::TOKEN_TOTALLY_CONSUMED,
109 1
            $event = new TokenTotallyConsumedEvent($token)
110
        );
111
112 1
        return $event;
113
    }
114
115
    /**
116
     * @param string $purpose
117
     * @param string $value
118
     *
119
     * @return TokenNotFoundEvent
120
     */
121 1
    public function tokenNotFound($purpose, $value)
122
    {
123 1
        $this->eventDispatcher->dispatch(
124 1
            TokenEvents::TOKEN_NOT_FOUND,
125 1
            $event = new TokenNotFoundEvent($purpose, $value)
126
        );
127
128 1
        return $event;
129
    }
130
131
    /**
132
     * @param string $purpose
133
     * @param string $value
134
     *
135
     * @return TokenExpiredEvent
136
     */
137 1
    public function tokenExpired($purpose, $value)
138
    {
139 1
        $this->eventDispatcher->dispatch(
140 1
            TokenEvents::TOKEN_EXPIRED,
141 1
            $event = new TokenExpiredEvent($purpose, $value)
142
        );
143
144 1
        return $event;
145
    }
146
147
    /**
148
     * @param string $purpose
149
     * @param string $value
150
     *
151
     * @return TokenAlreadyConsumedEvent
152
     */
153 1
    public function tokenAlreadyConsumed($purpose, $value)
154
    {
155 1
        $this->eventDispatcher->dispatch(
156 1
            TokenEvents::TOKEN_ALREADY_CONSUMED,
157 1
            $event = new TokenAlreadyConsumedEvent($purpose, $value)
158
        );
159
160 1
        return $event;
161
    }
162
163
    /**
164
     * @param Token $token
165
     *
166
     * @return TokenRetrievedEvent
167
     */
168 1
    public function tokenRetrieved(Token $token)
169
    {
170 1
        $this->eventDispatcher->dispatch(
171 1
            TokenEvents::TOKEN_RETRIEVED,
172 1
            $event = new TokenRetrievedEvent($token)
173
        );
174
175 1
        return $event;
176
    }
177
}
178