Failed Conditions
Push — master ( dbea68...9459a9 )
by Kentaro
01:14
created

ClassNameRepository::delete()   B

Complexity

Conditions 3
Paths 9

Size

Total Lines 30
Code Lines 21

Duplication

Lines 30
Ratio 100 %

Code Coverage

Tests 19
CRAP Score 3.0011

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 30
loc 30
ccs 19
cts 20
cp 0.95
rs 8.8571
cc 3
eloc 21
nc 9
nop 1
crap 3.0011
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\Repository;
26
27
use Doctrine\ORM\EntityRepository;
28
29
/**
30
 * ClassNameRepository
31
 *
32
 * This class was generated by the Doctrine ORM. Add your own custom
33
 * repository methods below.
34
 */
35
class ClassNameRepository extends EntityRepository
36
{
37
    /**
38
     * 規格一覧を取得する.
39
     *
40
     * @return array 規格の配列
41
     */
42 4
    public function getList()
43
    {
44 4
        $qb = $this->createQueryBuilder('cn')
45 4
            ->orderBy('cn.rank', 'DESC');
46 4
        $ClassNames = $qb->getQuery()
47 4
            ->getResult();
48
49 4
        return $ClassNames;
50
    }
51
52
    /**
53
     * 規格の順位を1上げる.
54
     *
55
     * @param  \Eccube\Entity\ClassName $ClassName
56
     * @return boolean 成功した場合 true
57
     */
58 2 View Code Duplication
    public function up(\Eccube\Entity\ClassName $ClassName)
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...
59
    {
60 2
        $em = $this->getEntityManager();
61 2
        $em->getConnection()->beginTransaction();
62
        try {
63 2
            $rank = $ClassName->getRank();
64
65
            //
66 2
            $ClassName2 = $this->findOneBy(array('rank' => $rank + 1));
67 2
            if (!$ClassName2) {
68 1
                throw new \Exception();
69
            }
70 1
            $ClassName2->setRank($rank);
71 1
            $em->persist($ClassName);
72
73
            // ClassName更新
74 1
            $ClassName->setRank($rank + 1);
75
76 1
            $em->persist($ClassName);
77 1
            $em->flush();
78
79 1
            $em->getConnection()->commit();
80 1
        } catch (\Exception $e) {
81 1
            $em->getConnection()->rollback();
82
83 1
            return false;
84
        }
85
86 1
        return true;
87
    }
88
89
    /**
90
     * 規格の順位を1下げる.
91
     *
92
     * @param \Eccube\Entity\ClassName $ClassName
93
     * @return boolean 成功した場合 true
94
     */
95 2 View Code Duplication
    public function down(\Eccube\Entity\ClassName $ClassName)
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...
96
    {
97 2
        $em = $this->getEntityManager();
98 2
        $em->getConnection()->beginTransaction();
99
        try {
100 2
            $rank = $ClassName->getRank();
101
102
            //
103 2
            $ClassName2 = $this->findOneBy(array('rank' => $rank - 1));
104 2
            if (!$ClassName2) {
105 1
                throw new \Exception();
106
            }
107 1
            $ClassName2->setRank($rank);
108 1
            $em->persist($ClassName);
109
110
            // ClassName更新
111 1
            $ClassName->setRank($rank - 1);
112
113 1
            $em->persist($ClassName);
114 1
            $em->flush();
115
116 1
            $em->getConnection()->commit();
117 1
        } catch (\Exception $e) {
118 1
            $em->getConnection()->rollback();
119
120 1
            return false;
121
        }
122
123 1
        return true;
124
    }
125
126
    /**
127
     * 規格を保存する.
128
     *
129
     * @param \Eccube\Entity\ClassName $ClassName
130
     * @return boolean 成功した場合 true
131
     */
132 6 View Code Duplication
    public function save(\Eccube\Entity\ClassName $ClassName)
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...
133
    {
134 6
        $em = $this->getEntityManager();
135 6
        $em->getConnection()->beginTransaction();
136
        try {
137 6
            if (!$ClassName->getId()) {
138 6
                $rank = $this->createQueryBuilder('cn')
139 6
                    ->select('MAX(cn.rank)')
140 6
                    ->getQuery()
141 6
                    ->getSingleScalarResult();
142 6
                if (!$rank) {
143 2
                    $rank = 0;
144
                }
145 6
                $ClassName->setRank($rank + 1);
146 6
                $ClassName->setDelFlg(0);
147
            }
148
149 6
            $em->persist($ClassName);
150 6
            $em->flush();
151
152 5
            $em->getConnection()->commit();
153 1
        } catch (\Exception $e) {
154 1
            $em->getConnection()->rollback();
155
156 1
            return false;
157
        }
158
159 5
        return true;
160
    }
161
162
    /**
163
     * 規格を削除する.
164
     *
165
     * @param \Eccube\Entity\ClassName $ClassName
166
     * @return boolean 成功した場合 true
167
     */
168 4 View Code Duplication
    public function delete(\Eccube\Entity\ClassName $ClassName)
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...
169
    {
170 4
        $em = $this->getEntityManager();
171 4
        $em->getConnection()->beginTransaction();
172
        try {
173 4
            if ($ClassName->getClassCategories()->count() > 0) {
174
                throw new \Exception();
175
            }
176
177 4
            $rank = $ClassName->getRank();
178 4
            $em->createQueryBuilder()
179 4
                ->update('Eccube\Entity\ClassName', 'cn')
180 4
                ->set('cn.rank', 'cn.rank - 1')
181 4
                ->where('cn.rank > :rank')->setParameter('rank', $rank)
182 4
                ->getQuery()
183 4
                ->execute();
184
185 4
            $ClassName->setDelFlg(1);
186 4
            $em->persist($ClassName);
187 4
            $em->flush();
188
189 3
            $em->getConnection()->commit();
190 1
        } catch (\Exception $e) {
191 1
            $em->getConnection()->rollback();
192
193 1
            return false;
194
        }
195
196 3
        return true;
197
    }
198
}
199