Completed
Push — master ( 749f69...94328c )
by Kamil
27:45
created

UserRegistrationFormSubscriber   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 6 1
A submit() 0 11 3
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\UserBundle\Form\EventSubscriber;
13
14
use Sylius\Component\User\Model\CustomerInterface;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
use Symfony\Component\Form\Exception\UnexpectedTypeException;
17
use Symfony\Component\Form\FormEvent;
18
use Symfony\Component\Form\FormEvents;
19
20
/**
21
 * @author Michał Marcinkowski <[email protected]>
22
 */
23
class UserRegistrationFormSubscriber implements EventSubscriberInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public static function getSubscribedEvents()
29
    {
30
        return [
31
            FormEvents::SUBMIT => 'submit',
32
        ];
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function submit(FormEvent $event)
39
    {
40
        $customer = $event->getData();
41
        if (!$customer instanceof CustomerInterface) {
42
            throw new UnexpectedTypeException($customer, CustomerInterface::class);
43
        }
44
45
        if (null !== $user = $customer->getUser()) {
46
            $user->setEnabled(true);
47
        }
48
    }
49
}
50