Failed Conditions
Branch master (23f88c)
by Kentaro
27:22
created

ClassNameController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 77
Duplicated Lines 62.34 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 72.72%
Metric Value
wmc 12
lcom 0
cbo 5
dl 48
loc 77
ccs 16
cts 22
cp 0.7272
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 20 20 3
B index() 14 38 6
A moveRank() 14 14 3

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
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Controller\Admin\Product;
26
27
use Eccube\Application;
28
use Eccube\Controller\AbstractController;
29
use Symfony\Component\HttpFoundation\Request;
30
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
31
32
class ClassNameController extends AbstractController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
33
{
34 3
    public function index(Application $app, Request $request, $id = null)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
35
    {
36 3
        if ($id) {
37
            $TargetClassName = $app['eccube.repository.class_name']->find($id);
38 1
            if (!$TargetClassName) {
39
                throw new NotFoundHttpException();
40
            }
41
        } else {
42
            $TargetClassName = new \Eccube\Entity\ClassName();
43 1
        }
44
45
        $form = $app['form.factory']
46
            ->createBuilder('admin_class_name', $TargetClassName)
47
            ->getForm();
48
49 View Code Duplication
        if ($request->getMethod() === 'POST') {
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...
50
            $form->handleRequest($request);
51
            if ($form->isValid()) {
52
                $status = $app['eccube.repository.class_name']->save($TargetClassName);
53
54 1
                if ($status) {
55
                    $app->addSuccess('admin.class_name.save.complete', 'admin');
56
57
                    return $app->redirect($app->url('admin_product_class_name'));
58
                } else {
59
                    $app->addError('admin.class_name.save.error', 'admin');
60
                }
61
            }
62
        }
63
64
        $ClassNames = $app['eccube.repository.class_name']->getList();
65
66 2
        return $app->render('Product/class_name.twig', array(
67 2
            'form' => $form->createView(),
68
            'ClassNames' => $ClassNames,
69
            'TargetClassName' => $TargetClassName,
70
        ));
71 3
    }
72
73 1 View Code Duplication
    public function delete(Application $app, Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
introduced by
Missing function doc comment
Loading history...
74
    {
75
        $this->isTokenValid($app);
76
77
        $TargetClassName = $app['eccube.repository.class_name']->find($id);
78 1
        if (!$TargetClassName) {
79
            $app->deleteMessage();
80
            return $app->redirect($app->url('admin_product_class_name'));
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
81
        }
82
83
        $status = $app['eccube.repository.class_name']->delete($TargetClassName);
84
85 1
        if ($status === true) {
86
            $app->addSuccess('admin.class_name.delete.complete', 'admin');
87
        } else {
88
            $app->addError('admin.class_name.delete.error', 'admin');
89 1
        }
90
91
        return $app->redirect($app->url('admin_product_class_name'));
92 1
    }
93
94 1 View Code Duplication
    public function moveRank(Application $app, 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...
introduced by
Missing function doc comment
Loading history...
95
    {
96
        if ($request->isXmlHttpRequest()) {
97
            $ranks = $request->request->all();
98
            foreach ($ranks as $classNameId => $rank) {
99
                $ClassName = $app['eccube.repository.class_name']
100
                    ->find($classNameId);
101
                $ClassName->setRank($rank);
102
                $app['orm.em']->persist($ClassName);
103
            }
104
            $app['orm.em']->flush();
105
        }
106 1
        return true;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
107 1
    }
108
}
109