SecurityController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 95.45%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 49
ccs 21
cts 22
cp 0.9545
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B indexAction() 0 29 5
A logoutAction() 0 8 1
1
<?php
2
3
/*
4
 * This file is part of the "Kata 1" package.
5
 *
6
 * Copyright (c) Daniel González
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @author Daniel González <[email protected]>
12
 */
13
14
namespace App\Controller;
15
16
use Component\Http\RedirectResponse;
17
use Component\Http\Request;
18
use Component\Http\Session;
19
20
use App\Repository\UserRepository;
21
22
/**
23
 * SecurityController.
24
 */
25
class SecurityController extends AppController
26
{
27
    /**
28
     * @param Request $request
29
     *
30
     * @return Response
31
     */
32 5
    public function indexAction(Request $request)
33
    {
34
        /* @var Session */
35 5
        $session = $this->app['app.session'];
36 5
        $user = $session->getUser();
37 5
        if ($user) {
38
            return new RedirectResponse('/');
39
        }
40 5
        if ($request->getMethod() == 'POST') {
41
            /* @var UserRepository */
42 5
            $repository = $this->app['app.repository.user'];
43
44 5
            $user = $repository->findByNameAndPassword(
45 5
                $request->get('post', 'name', false),
46 5
                $request->get('post', 'password', false)
47 5
            );
48 5
            if (!$user) {
49 1
                return $this->render('Login\\index.html.twig', ['error' => 'Name or password invalid']);
50
            }
51 4
            $session->setUser($user);
52 4
            if ($session->has('app.redirect_on_login')) {
53 2
                return new RedirectResponse($session->get('app.redirect_on_login'));
54
            }
55
56 2
            return new RedirectResponse('/');
57
        }
58
59 5
        return $this->render('Login\\index.html.twig', []);
60
    }
61
62
    /**
63
     * @return RedirectResponse
64
     */
65 4
    public function logoutAction()
66
    {
67
        /* @var Session */
68 4
        $session = $this->app['app.session'];
69 4
        $session->close();
70
71 4
        return new RedirectResponse('/login');
72
    }
73
}
74