SecurityController::login()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 13
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 21
ccs 0
cts 18
cp 0
crap 30
rs 9.5222
1
<?php
2
namespace App\Controller\Security;
3
4
use App\Form\Type\UserLoginType;
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\Routing\Annotation\Route;
7
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
8
use Symfony\Component\Form\FormError;
9
10
class SecurityController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

10
class SecurityController extends /** @scrutinizer ignore-deprecated */ Controller
Loading history...
11
{
12
    /**
13
     * @Route("/login", name="login", methods={"GET", "POST"})
14
     */
15
    public function login(AuthenticationUtils $authenticationUtils)
16
    {
17
        $error = $authenticationUtils->getLastAuthenticationError();
18
        $lastUsername = $authenticationUtils->getLastUsername();
19
        $form = $this->createForm(UserLoginType::class);
20
21
        if ($error) {
22
            $error = new FormError("There is an error: " . $error->getMessage());
23
            $form->addError($error);
24
        };
25
26
        if ($form->isSubmitted() && $form->isValid() && !$error) {
27
            return $this->redirectToRoute('admin_dashboard');
28
        }
29
        
30
        return $this->render(
31
            'security/login.html.twig',
32
            [
33
                'form'          => $form->createView(),
34
                'last_username' => $lastUsername,
35
                'error'         => $error,
36
            ]
37
        );
38
    }
39
40
    /**
41
     * @Route("/logout", name="logout", methods={"GET"})
42
     */
43
    public function logout()
44
    {
45
        // controller can be blank: it will never be executed!
46
        throw new \Exception('Don\'t forget to activate logout in security.yaml');
47
    }
48
}