Failed Conditions
Pull Request — experimental/sf (#3236)
by Kentaro
48:27
created

TestController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 15
loc 65
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 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
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Acme\Controller;
15
16
use Eccube\Application;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\HttpFoundation\Request;
19
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
20
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
21
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
22
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
23
24
/**
25
 * @Route("/test")
26
 * @Template("test/index.twig")
27
 */
28
class TestController
29
{
30
    /**
31
     * @Method("GET")
32
     * @Route("/detail2/{id}", requirements={"id" = "\d+"})
33
     * //@Security("has_role('ROLE_ADMIN')")
34
     */
35
    public function testMethod(Application $app, Request $request, $id = 0)
36
    {
37
        return new Response('test Method: '.$id);
38
    }
39
40
    /**
41
     * @Route("/initialize/{id}", requirements={"id" = "\d+"})
42
     */
43
    public function initialize(Application $app, Request $request, $id = 0)
44
    {
45
        dump('initialize');
46
        $t = new \Eccube\Entity\Csv();
47
        $t->getDispName($id);
48
49
        return $app->forward($app->path('test/new'), ['param_init' => $id]);
50
    }
51
52
    /**
53
     * @Method("GET")
54
     * @Route("/", name="test/index")
55
     */
56
    public function index(Application $app, Request $request)
57
    {
58
        dump('/');
59
        $id = 1;
60
        $app->forwardChain('/test/initialize/'.$id)
61
            ->forwardchain($app->path('test/new'), ['param_init' => $id], $response)
62
            ->forwardChain($app->path('test/new'), ['param_init' => $id], $response)
63
            ->forwardChain($app->path('test/new'), ['param_init' => $id], $response);
64
65
        return $response;
66
    }
67
68
    /**
69
     * @Method("GET")
70
     * @Route("/new", name="test/new")
71
     */
72
    public function newAction(Application $app, Request $request)
73
    {
74
        dump('new');
75
        $t = $app['request_scope']->get('csv');
76
        dump($t);
77
78
        return ['id' => $t->getDispName()];
79
    }
80
81
    /**
82
     * @Method("GET")
83
     * @Route("/post")
84
     */
85
    public function postAction(Application $app, Request $request)
86
    {
87
        dump('post');
88
        $app->forward('/test/initialize/5');
89
90
        return ['id' => $app['request_scope']->get('csv')->getDispName()];
91
    }
92
}
93