UserEventResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 14
c 2
b 0
f 0
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getEventLogDetails() 0 5 2
A getEventLogInfo() 0 13 2
1
<?php
2
3
/*
4
 * This file is part of the XiideaEasyAuditBundle package.
5
 *
6
 * (c) Xiidea <http://www.xiidea.net>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Xiidea\EasyAuditBundle\Resolver;
13
14
use Symfony\Contracts\EventDispatcher\Event;
15
use Xiidea\EasyAuditBundle\Common\UserAwareComponent;
16
use Xiidea\EasyAuditBundle\Resolver\UserEventCommand\InteractiveLoginCommand;
17
use Xiidea\EasyAuditBundle\Resolver\UserEventCommand\ResolverCommand;
18
19
/** Custom Event Resolver Example For FosUserBundle  */
20
class UserEventResolver extends UserAwareComponent implements EventResolverInterface
21
{
22
    private $commands = array();
23
24
    private $default;
25
26
    public function __construct()
27
    {
28
        $this->commands = array(
29
            'security.interactive_login' => new InteractiveLoginCommand($this)
30
        );
31
    }
32
33
    /**
34
     * @param Event $event
35
     * @param $eventName
36
     *
37
     * @return array
38
     */
39
    #[\Override]
40
    public function getEventLogInfo(Event $event, $eventName)
41
    {
42
        $this->default = array(
43
            'type' => $eventName,
44
            'description' => $eventName,
45
        );
46
47
        if (!isset($this->commands[$eventName])) {
48
            return $this->default;
49
        }
50
51
        return $this->getEventLogDetails($event, $this->commands[$eventName]);
52
    }
53
54
    /**
55
     * @param Event           $event
56
     * @param ResolverCommand $command
57
     *
58
     * @return array
59
     */
60
    protected function getEventLogDetails(Event $event, ResolverCommand $command)
61
    {
62
        $details = $command->resolve($event);
63
64
        return empty($details) ? $this->default : $details;
65
    }
66
}
67