These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of EC-CUBE |
||
5 | * |
||
6 | * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
||
7 | * |
||
8 | * http://www.ec-cube.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 Eccube\Repository; |
||
15 | |||
16 | use Doctrine\DBAL\Exception\DriverException; |
||
17 | use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; |
||
18 | use Eccube\Entity\Member; |
||
19 | use Symfony\Bridge\Doctrine\RegistryInterface; |
||
20 | |||
21 | /** |
||
22 | * MemberRepository |
||
23 | * |
||
24 | * This class was generated by the Doctrine ORM. Add your own custom |
||
25 | * repository methods below. |
||
26 | */ |
||
27 | class MemberRepository extends AbstractRepository |
||
28 | { |
||
29 | 795 | public function __construct(RegistryInterface $registry) |
|
30 | { |
||
31 | 795 | parent::__construct($registry, Member::class); |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * 管理ユーザの表示順を一つ上げる. |
||
36 | * |
||
37 | * @param Member $Member |
||
38 | * |
||
39 | * @throws \Exception 更新対象のユーザより上位のユーザが存在しない場合. |
||
40 | */ |
||
41 | 4 | View Code Duplication | public function up(Member $Member) |
0 ignored issues
–
show
|
|||
42 | { |
||
43 | 4 | $sortNo = $Member->getSortNo(); |
|
44 | 4 | $Member2 = $this->findOneBy(['sort_no' => $sortNo + 1]); |
|
45 | |||
46 | 4 | if (!$Member2) { |
|
47 | 2 | throw new \Exception(sprintf('%s より上位の管理ユーザが存在しません.', $Member->getId())); |
|
48 | } |
||
49 | |||
50 | 2 | $Member->setSortNo($sortNo + 1); |
|
51 | 2 | $Member2->setSortNo($sortNo); |
|
52 | |||
53 | 2 | $em = $this->getEntityManager(); |
|
54 | 2 | $em->flush([$Member, $Member2]); |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * 管理ユーザの表示順を一つ下げる. |
||
59 | * |
||
60 | * @param Member $Member |
||
61 | * |
||
62 | * @throws \Exception 更新対象のユーザより下位のユーザが存在しない場合. |
||
63 | */ |
||
64 | 5 | View Code Duplication | public function down(Member $Member) |
0 ignored issues
–
show
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...
|
|||
65 | { |
||
66 | 5 | $sortNo = $Member->getSortNo(); |
|
67 | 5 | $Member2 = $this->findOneBy(['sort_no' => $sortNo - 1]); |
|
68 | |||
69 | 5 | if (!$Member2) { |
|
70 | 2 | throw new \Exception(sprintf('%s より下位の管理ユーザが存在しません.', $Member->getId())); |
|
71 | } |
||
72 | |||
73 | 3 | $Member->setSortNo($sortNo - 1); |
|
74 | 3 | $Member2->setSortNo($sortNo); |
|
75 | |||
76 | 3 | $em = $this->getEntityManager(); |
|
77 | 3 | $em->flush([$Member, $Member2]); |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * 管理ユーザを登録します. |
||
82 | * |
||
83 | * @param Member $Member |
||
84 | */ |
||
85 | 299 | public function save($Member) |
|
86 | { |
||
87 | 299 | if (!$Member->getId()) { |
|
88 | 299 | $sortNo = $this->createQueryBuilder('m') |
|
89 | 299 | ->select('COALESCE(MAX(m.sort_no), 0)') |
|
90 | 299 | ->getQuery() |
|
91 | 299 | ->getSingleScalarResult(); |
|
92 | $Member |
||
93 | 299 | ->setSortNo($sortNo + 1); |
|
94 | } |
||
95 | |||
96 | 299 | $em = $this->getEntityManager(); |
|
97 | 299 | $em->persist($Member); |
|
98 | 299 | $em->flush($Member); |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * 管理ユーザを削除します. |
||
103 | * |
||
104 | * @param Member $Member |
||
105 | * |
||
106 | * @throws ForeignKeyConstraintViolationException 外部キー制約違反の場合 |
||
107 | * @throws DriverException SQLiteの場合, 外部キー制約違反が発生すると, DriverExceptionをthrowします. |
||
108 | */ |
||
109 | 2 | View Code Duplication | public function delete($Member) |
0 ignored issues
–
show
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...
|
|||
110 | { |
||
111 | 2 | $this->createQueryBuilder('m') |
|
112 | 2 | ->update() |
|
113 | 2 | ->set('m.sort_no', 'm.sort_no - 1') |
|
114 | 2 | ->where('m.sort_no > :sort_no') |
|
115 | 2 | ->setParameter('sort_no', $Member->getSortNo()) |
|
116 | 2 | ->getQuery() |
|
117 | 2 | ->execute(); |
|
118 | |||
119 | 2 | $em = $this->getEntityManager(); |
|
120 | 2 | $em->remove($Member); |
|
121 | 2 | $em->flush($Member); |
|
122 | } |
||
123 | } |
||
124 |
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.