Completed
Pull Request — master (#2)
by Andrew
04:30
created

SecurityController::registerAction()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 15

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 19
loc 19
ccs 0
cts 19
cp 0
rs 9.4285
cc 3
eloc 15
nc 2
nop 1
crap 12
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
use AppBundle\Form\UserType;
8
use AppBundle\Entity\User;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class SecurityController extends Controller
12
{
13
    /**
14
     * @Route("/login", name="security_login_form")
15
     */
16
    public function loginAction()
17
    {
18
        $helper = $this->get('security.authentication_utils');
19
20
        return $this->render('AppBundle:security:login.html.twig', array(
21
            'last_username' => $helper->getLastUsername(),
22
            'error' => $helper->getLastAuthenticationError(),
23
        ));
24
    }
25
26
    /**
27
     * @Route("/register", name="user_registration")
28
     */
29 View Code Duplication
    public function registerAction(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31
        $user = new User();
32
        $form = $this->createForm(UserType::class, $user);
33
        $form->handleRequest($request);
34
        if ($form->isSubmitted() && $form->isValid()) {
35
            $password = $this->get('security.password_encoder')
36
                ->encodePassword($user, $user->getPlainPassword());
37
            $user->setPassword($password);
38
            $em = $this->getDoctrine()->getManager();
39
            $em->persist($user);
40
            $em->flush();
41
            return $this->redirectToRoute('security_login_form');
42
        }
43
        return $this->render(
44
            'AppBundle:security:register.html.twig',
45
            array('form' => $form->createView())
46
        );
47
    }
48
49
    /**
50
     * @Route("/login_check", name="security_login_check")
51
     */
52
    public function loginCheckAction()
53
    {
54
        throw new \Exception('This should never be reached!');
55
    }
56
57
58
}
59