UserValidatedSubscriber   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validateUser() 0 6 1
A sendFlash() 0 3 1
A getSubscribedEvents() 0 7 1
1
<?php
2
3
namespace App\EventSubscriber\User;
4
5
use App\Entity\User;
6
use App\Event\User\UserValidatedEvent;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9
class UserValidatedSubscriber extends AbstractUserSubscriber implements EventSubscriberInterface
10
{
11
12
13
    public function validateUser(UserValidatedEvent $event)
14
    {
15
        /** @var User $user */
16
        $user = $event->getEntity();
17
        $user->setVerified(true);
18
        $this->persist($event);
19
    }
20
21
    public function sendFlash()
22
    {
23
        $this->addFlashMessage('success', 'Account is verified');
24
    }
25
26
27
    /**
28
     * @return array The event names to listen to
29
     */
30
    public static function getSubscribedEvents()
31
    {
32
        return [
33
            UserValidatedEvent::NAME => [
34
                ['validateUser', 40],
35
                ['flush', 20],
36
                ['sendFlash', 0],
37
            ]
38
        ];
39
    }
40
}