U2fPostRegistrationEvent::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the U2F Security bundle.
5
 *
6
 * (c) Michael Barbey <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mbarbey\U2fSecurityBundle\Event\Registration;
13
14
use Symfony\Component\EventDispatcher\Event;
15
use Mbarbey\U2fSecurityBundle\Model\User\U2fUserInterface;
16
use Mbarbey\U2fSecurityBundle\Model\Key\U2fKeyInterface;
17
18
/**
19
 * Post U2F registration event
20
 *
21
 * An event dispatched everytime the registration of a security key is performed, no matter if it was a success or a failure.
22
 *
23
 * This event contain the user who tried to register a key and *can* contain the key if the registration was a success.
24
 *
25
 * @author Michael Barbey <[email protected]>
26
 */
27
28
class U2fPostRegistrationEvent extends Event
29
{
30
    private $user;
31
    private $key;
32
    private $success = false;
33
34
    /**
35
     * Return the name of the event to use when dispatching this event.
36
     *
37
     * @return string
38
     */
39 1
    public static function getName()
40
    {
41 1
        return 'u2f.registration.after';
42
    }
43
44
    /**
45
     * @param U2fUserInterface $user    The user who tried to register a key
46
     * @param U2fKeyInterface $key      The security key which was registered
47
     */
48 4
    public function __construct(U2fUserInterface $user, U2fKeyInterface $key = null)
49
    {
50 4
        $this->user = $user;
51
52 4
        if ($key) {
53 4
            $this->key = $key;
54 4
            $this->success = true;
55
        }
56 4
    }
57
58
    /**
59
     * Return the user who tried to register a key, no matter if it was a success or not.
60
     *
61
     * @return U2fUserInterface
62
     */
63 1
    public function getUser()
64
    {
65 1
        return $this->user;
66
    }
67
68
    /**
69
     * If the registration was a success, then return the key registered, else return nothing.
70
     *
71
     * @return U2fKeyInterface|NULL
72
     */
73 1
    public function getKey()
74
    {
75 1
        return $this->key;
76
    }
77
78
    /**
79
     * Inform if the key registration was a success or a failure.
80
     *
81
     * @return bool
82
     */
83 1
    public function isSuccess()
84
    {
85 1
        return $this->success;
86
    }
87
}
88