U2fPostAuthenticationEvent::getUser()   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\Authentication;
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 authentication event
20
 *
21
 * An event dispatched everytime an authentication is performed, no matter if it was a success or a failure.
22
 *
23
 * This event contain the user who tried to authenticate and *can* contain the key if the authentication was a success.
24
 * The counter of the key is already updated.
25
 *
26
 * @author Michael Barbey <[email protected]>
27
 */
28
class U2fPostAuthenticationEvent 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.authentication.after';
42
    }
43
44
    /**
45
     * @param U2fUserInterface $user    The user who tried to authenticate
46
     * @param U2fKeyInterface $key      The key used if the authentication was a success
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 authenticate, 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 authentication was a success, then return the key used, else return nothing.
70
     * The counter of the key is already updated.
71
     *
72
     * @return U2fKeyInterface|NULL
73
     */
74 1
    public function getKey()
75
    {
76 1
        return $this->key;
77
    }
78
79
    /**
80
     * Inform if the authentication was a success or a failure.
81
     *
82
     * @return bool
83
     */
84 1
    public function isSuccess()
85
    {
86 1
        return $this->success;
87
    }
88
}
89