Completed
Push — master ( 402c8e...a49823 )
by Philip
22:11
created

DefaultController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 38
Duplicated Lines 42.11 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 10
c 0
b 0
f 0
lcom 1
cbo 4
dl 16
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 4 1
C loginAction() 16 22 8
A loggedoutAction() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Controller;
4
5
use Dontdrinkandroot\GitkiBundle\Controller\BaseController;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\Security\Core\Exception\AuthenticationException;
9
10
class DefaultController extends BaseController
11
{
12
    public function indexAction()
13
    {
14
        return $this->redirect($this->generateUrl('ddr_gitki_directory', ['path' => '/', 'action' => 'index']));
15
    }
16
17
    public function loginAction(Request $request)
18
    {
19 View Code Duplication
        if (!$this->isGranted('ROLE_USER')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
20
            if ($request->hasSession() && $request->isMethodSafe()) {
21
                $referer = $request->headers->get('referer');
22
                if (null !== $referer) {
23
                    $request->getSession()->set('ddr.gitki.manuallogin.targetpath', $referer);
24
                }
25
            }
26
            throw new AuthenticationException();
27
        }
28
29 View Code Duplication
        if ($request->hasSession() && $request->isMethodSafe()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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
            $targetPath = $request->getSession()->get('ddr.gitki.manuallogin.targetpath');
31
            $request->getSession()->remove('ddr.gitki.manuallogin.targetpath');
32
            if (null !== $targetPath) {
33
                return $this->redirect($targetPath);
34
            }
35
        }
36
37
        return $this->redirect($this->generateUrl('ddr_gitki_directory', ['path' => '/', 'action' => 'index']));
38
    }
39
40
    /**
41
     * @return Response
42
     */
43
    public function loggedoutAction()
44
    {
45
        return $this->render('DdrGitkiWebBundle:Default:loggedout.html.twig');
46
    }
47
}
48