Completed
Pull Request — master (#2050)
by
unknown
39:48
created

OrderRepository   D

Complexity

Total Complexity 102

Size/Duplication

Total Lines 486
Duplicated Lines 54.12 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 97.58%

Importance

Changes 0
Metric Value
dl 263
loc 486
ccs 242
cts 248
cp 0.9758
rs 4.8717
c 0
b 0
f 0
wmc 102
lcom 1
cbo 6

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setApplication() 0 4 1
A changeStatus() 0 20 3
F getQueryBuilderBySearchData() 124 183 46
F getQueryBuilderBySearchDataForAdmin() 139 201 49
A getQueryBuilderByCustomer() 0 11 1
A getNew() 0 13 1
A getCustomerCount() 0 15 1

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like OrderRepository often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use OrderRepository, and based on these observations, apply Extract Interface, too.

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 Eccube\Util\Str;
28
use Doctrine\ORM\EntityRepository;
29
use Doctrine\ORM\QueryBuilder;
30
31
/**
32
 * OrderRepository
33
 *
34
 * This class was generated by the Doctrine ORM. Add your own custom
35
 * repository methods below.
36
 */
37
class OrderRepository extends EntityRepository
38
{
39
    protected $app;
40
41 137
    public function setApplication($app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
42
    {
43 137
        $this->app = $app;
44
    }
45
46 7
    public function changeStatus($orderId, \Eccube\Entity\Master\OrderStatus $Status)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
47
    {
48
        $Order = $this
49 7
            ->find($orderId)
50 7
            ->setOrderStatus($Status)
51
        ;
52
53 7
        switch ($Status->getId()) {
54 7
            case '5': // 発送済へ
55 3
                $Order->setCommitDate(new \DateTime());
56 3
                break;
57 4
            case '6': // 入金済へ
58 3
                $Order->setPaymentDate(new \DateTime());
59 7
                break;
60
        }
61
62 7
        $em = $this->getEntityManager();
63 7
        $em->persist($Order);
64 7
        $em->flush();
65
    }
66
67
    /**
68
     *
69
     * @param  array        $searchData
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
70
     * @return QueryBuilder
71
     */
72 19
    public function getQueryBuilderBySearchData($searchData)
73
    {
74 19
        $qb = $this->createQueryBuilder('o');
75
76 19
        $joinedCustomer = false;
77
78
        // order_id_start
79 19 View Code Duplication
        if (isset($searchData['order_id_start']) && Str::isNotBlank($searchData['order_id_start'])) {
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...
80
            $qb
81 1
                ->andWhere('o.id >= :order_id_start')
82 1
                ->setParameter('order_id_start', $searchData['order_id_start']);
83
        }
84
85
        // order_id_end
86 19 View Code Duplication
        if (isset($searchData['order_id_end']) && Str::isNotBlank($searchData['order_id_end'])) {
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...
87
            $qb
88 1
                ->andWhere('o.id <= :order_id_end')
89 1
                ->setParameter('order_id_end', $searchData['order_id_end']);
90
        }
91
92
        // status
93 19
        if (!empty($searchData['status']) && $searchData['status']) {
94
            $qb
95 1
                ->andWhere('o.OrderStatus = :status')
96 1
                ->setParameter('status', $searchData['status']);
97
        }
98
99
        // name
100 19 View Code Duplication
        if (isset($searchData['name']) && Str::isNotBlank($searchData['name'])) {
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...
101
            $qb
102 1
                ->andWhere('CONCAT(o.name01, o.name02) LIKE :name')
103 1
                ->setParameter('name', '%' . $searchData['name'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
104
        }
105
106
        // kana
107 19 View Code Duplication
        if (isset($searchData['kana']) && Str::isNotBlank($searchData['kana'])) {
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...
108
            $qb
109 1
                ->andWhere('CONCAT(o.kana01, o.kana02) LIKE :kana')
110 1
                ->setParameter('kana', '%' . $searchData['kana'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
111
        }
112
113
        // email
114 19 View Code Duplication
        if (isset($searchData['email']) && Str::isNotBlank($searchData['email'])) {
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...
115
            $qb
116 1
                ->andWhere('o.email = :email')
117 1
                ->setParameter('email', $searchData['email']);
118
        }
119
120
        // tel
121 19 View Code Duplication
        if (isset($searchData['tel01']) && Str::isNotBlank($searchData['tel01'])) {
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...
122
            $qb
123 1
                ->andWhere('o.tel01 = :tel01')
124 1
                ->setParameter('tel01', $searchData['tel01']);
125
        }
126 19 View Code Duplication
        if (isset($searchData['tel02']) && Str::isNotBlank($searchData['tel02'])) {
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...
127
            $qb
128 1
                ->andWhere('o.tel02 = :tel02')
129 1
                ->setParameter('tel02', $searchData['tel02']);
130
        }
131 19 View Code Duplication
        if (isset($searchData['tel03']) && Str::isNotBlank($searchData['tel03'])) {
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...
132
            $qb
133 1
                ->andWhere('o.tel03 = :tel03')
134 1
                ->setParameter('tel03', $searchData['tel03']);
135
        }
136
137
        // birth
138 19 View Code Duplication
        if (!empty($searchData['birth_start']) && $searchData['birth_start']) {
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...
139 1
            if (!$joinedCustomer) {
140 1
                $qb->leftJoin('o.Customer', 'c');
141 1
                $joinedCustomer = true;
142
            }
143
144 1
            $date = $searchData['birth_start']
145 1
                ->format('Y-m-d H:i:s');
146
            $qb
147 1
                ->andWhere('c.birth >= :birth_start')
148 1
                ->setParameter('birth_start', $date);
149
        }
150 19 View Code Duplication
        if (!empty($searchData['birth_end']) && $searchData['birth_end']) {
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...
151 1
            if (!$joinedCustomer) {
152 1
                $qb->leftJoin('o.Customer', 'c');
153 1
                $joinedCustomer = true;
154
            }
155
156 1
            $date = clone $searchData['birth_end'];
157
            $date = $date
158 1
                ->modify('+1 days')
159 1
                ->format('Y-m-d H:i:s');
160
            $qb
161 1
                ->andWhere('c.birth < :birth_end')
162 1
                ->setParameter('birth_end', $date);
163
        }
164
165
        // sex
166 19
        if (!empty($searchData['sex']) && count($searchData['sex']) > 0) {
167 1
            if (!$joinedCustomer) {
168 1
                $qb->leftJoin('o.Customer', 'c');
169 1
                $joinedCustomer = true;
0 ignored issues
show
Unused Code introduced by
$joinedCustomer is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
170
            }
171
172 1
            $sexs = array();
173 1
            foreach ($searchData['sex'] as $sex) {
174 1
                $sexs[] = $sex->getId();
175
            }
176
177
            $qb
178 1
                ->andWhere($qb->expr()->in('c.Sex', ':sexs'))
179 1
                ->setParameter('sexs', $sexs);
180
        }
181
182
        // payment
183 19 View Code Duplication
        if (!empty($searchData['payment']) && count($searchData['payment'])) {
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...
184
            $payments = array();
185
            foreach ($searchData['payment'] as $payment) {
186
                $payments[] = $payment->getId();
187
            }
188
            $qb
189
                ->leftJoin('o.Payment', 'p')
190
                ->andWhere($qb->expr()->in('p.id', ':payments'))
191
                ->setParameter('payments', $payments);
192
        }
193
194
        // oreder_date
195 19 View Code Duplication
        if (!empty($searchData['order_date_start']) && $searchData['order_date_start']) {
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...
196 1
            $date = $searchData['order_date_start']
197 1
                ->format('Y-m-d H:i:s');
198
            $qb
199 1
                ->andWhere('o.create_date >= :order_date_start')
200 1
                ->setParameter('order_date_start', $date);
201
        }
202 19 View Code Duplication
        if (!empty($searchData['order_date_end']) && $searchData['order_date_end']) {
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...
203 1
            $date = clone $searchData['order_date_end'];
204
            $date = $date
205 1
                ->modify('+1 days')
206 1
                ->format('Y-m-d H:i:s');
207
            $qb
208 1
                ->andWhere('o.create_date < :order_date_end')
209 1
                ->setParameter('order_date_end', $date);
210
        }
211
212
        // create_date
213 19 View Code Duplication
        if (!empty($searchData['update_date_start']) && $searchData['update_date_start']) {
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...
214 1
            $date = $searchData['update_date_start']
215 1
                ->format('Y-m-d H:i:s');
216
            $qb
217 1
                ->andWhere('o.update_date >= :update_date_start')
218 1
                ->setParameter('update_date_start', $date);
219
        }
220 19 View Code Duplication
        if (!empty($searchData['update_date_end']) && $searchData['update_date_end']) {
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...
221 1
            $date = clone $searchData['update_date_end'];
222
            $date = $date
223 1
                ->modify('+1 days')
224 1
                ->format('Y-m-d H:i:s');
225
            $qb
226 1
                ->andWhere('o.update_date < :update_date_end')
227 1
                ->setParameter('update_date_end', $date);
228
        }
229
230
        // payment_total
231 19 View Code Duplication
        if (isset($searchData['payment_total_start']) && Str::isNotBlank($searchData['payment_total_start'])) {
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...
232
            $qb
233 1
                ->andWhere('o.payment_total >= :payment_total_start')
234 1
                ->setParameter('payment_total_start', $searchData['payment_total_start']);
235
        }
236 19 View Code Duplication
        if (isset($searchData['payment_total_end']) && Str::isNotBlank($searchData['payment_total_end'])) {
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...
237
            $qb
238 1
                ->andWhere('o.payment_total <= :payment_total_end')
239 1
                ->setParameter('payment_total_end', $searchData['payment_total_end']);
240
        }
241
242
        // buy_product_name
243 19 View Code Duplication
        if (isset($searchData['buy_product_name']) && Str::isNotBlank($searchData['buy_product_name'])) {
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...
244
            $qb
245 1
                ->leftJoin('o.OrderDetails', 'od')
246 1
                ->andWhere('od.product_name LIKE :buy_product_name')
247 1
                ->setParameter('buy_product_name', '%' . $searchData['buy_product_name'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
248
        }
249
250
        // Order By
251 19
        $qb->addOrderBy('o.update_date', 'DESC');
252
253 19
        return $qb;
254
    }
255
256
257
    /**
258
     *
259
     * @param  array        $searchData
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
260
     * @return QueryBuilder
261
     */
262 32
    public function getQueryBuilderBySearchDataForAdmin($searchData)
263
    {
264 32
        $qb = $this->createQueryBuilder('o');
265
266
        // order_id_start
267 32 View Code Duplication
        if (isset($searchData['order_id_start']) && Str::isNotBlank($searchData['order_id_start'])) {
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...
268
            $qb
269 1
                ->andWhere('o.id >= :order_id_start')
270 1
                ->setParameter('order_id_start', $searchData['order_id_start']);
271
        }
272
        // multi
273 32 View Code Duplication
        if (isset($searchData['multi']) && Str::isNotBlank($searchData['multi'])) {
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...
274 5
            $multi = preg_match('/^\d+$/', $searchData['multi']) ? $searchData['multi'] : null;
275 5
            if ($multi === null) {
276
                $qb
277 3
                    ->andWhere('o.name01 LIKE :likemulti OR o.name02 LIKE :likemulti OR ' .
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
278 3
                        'o.kana01 LIKE :likemulti OR o.kana02 LIKE :likemulti OR o.company_name LIKE :likemulti')
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 20 spaces, but found 24.
Loading history...
279 3
                    ->setParameter('likemulti', '%' . $searchData['multi'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
280
            } else {
281
                $qb
282 2
                    ->andWhere('o.id = :multi')
283 2
                    ->setParameter('multi', $multi);
284
            }
285
        }
286
287
        // order_id_end
288 32 View Code Duplication
        if (isset($searchData['order_id_end']) && Str::isNotBlank($searchData['order_id_end'])) {
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...
289
            $qb
290 1
                ->andWhere('o.id <= :order_id_end')
291 1
                ->setParameter('order_id_end', $searchData['order_id_end']);
292
        }
293
294
        // status
295 32
        $filterStatus = false;
296 32 View Code Duplication
        if (!empty($searchData['status']) && $searchData['status']) {
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...
297
            $qb
298 3
                ->andWhere('o.OrderStatus = :status')
299 3
                ->setParameter('status', $searchData['status']);
300 3
            $filterStatus = true;
301
        }
302 32
        if (!empty($searchData['multi_status']) && count($searchData['multi_status'])) {
303
            $qb
304 1
                ->andWhere($qb->expr()->in('o.OrderStatus', ':multi_status'))
305 1
                ->setParameter('multi_status', $searchData['multi_status']->toArray());
306 1
            $filterStatus = true;
307
        }
308 32
        if (!$filterStatus) {
309
            // 購入処理中は検索対象から除外
310 28
            $OrderStatuses = $this->getEntityManager()
311 28
                ->getRepository('Eccube\Entity\Master\OrderStatus')
312 28
                ->findNotContainsBy(array('id' => $this->app['config']['order_processing']));
313 28
            $qb->andWhere($qb->expr()->in('o.OrderStatus', ':status'))
314 28
                ->setParameter('status', $OrderStatuses);
315
        }
316
317
        // name
318 32 View Code Duplication
        if (isset($searchData['name']) && Str::isNotBlank($searchData['name'])) {
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...
319
            $qb
320 1
                ->andWhere('CONCAT(o.name01, o.name02) LIKE :name')
321 1
                ->setParameter('name', '%' . $searchData['name'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
322
        }
323
324
        // kana
325 32 View Code Duplication
        if (isset($searchData['kana']) && Str::isNotBlank($searchData['kana'])) {
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...
326
            $qb
327 1
                ->andWhere('CONCAT(o.kana01, o.kana02) LIKE :kana')
328 1
                ->setParameter('kana', '%' . $searchData['kana'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
329
        }
330
331
        // email
332 32 View Code Duplication
        if (isset($searchData['email']) && Str::isNotBlank($searchData['email'])) {
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...
333
            $qb
334 2
                ->andWhere('o.email like :email')
335 2
                ->setParameter('email', '%' . $searchData['email'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
336
        }
337
338
        // tel
339 32 View Code Duplication
        if (isset($searchData['tel']) && Str::isNotBlank($searchData['tel'])) {
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...
340
            $qb
341 1
                ->andWhere('CONCAT(o.tel01, o.tel02, o.tel03) LIKE :tel')
342 1
                ->setParameter('tel', '%' . $searchData['tel'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
343
        }
344
345
        // sex
346 32
        if (!empty($searchData['sex']) && count($searchData['sex']) > 0) {
347
            $qb
348 3
                ->andWhere($qb->expr()->in('o.Sex', ':sex'))
349 3
                ->setParameter('sex', $searchData['sex']->toArray());
350
        }
351
352
        // payment
353 32 View Code Duplication
        if (!empty($searchData['payment']) && count($searchData['payment'])) {
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...
354 2
            $payments = array();
355 2
            foreach ($searchData['payment'] as $payment) {
356 2
                $payments[] = $payment->getId();
357
            }
358
            $qb
359 2
                ->leftJoin('o.Payment', 'p')
360 2
                ->andWhere($qb->expr()->in('p.id', ':payments'))
361 2
                ->setParameter('payments', $payments);
362
        }
363
364
        // oreder_date
365 32 View Code Duplication
        if (!empty($searchData['order_date_start']) && $searchData['order_date_start']) {
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...
366 1
            $date = $searchData['order_date_start']
367 1
                ->format('Y-m-d H:i:s');
368
            $qb
369 1
                ->andWhere('o.order_date >= :order_date_start')
370 1
                ->setParameter('order_date_start', $date);
371
        }
372 32 View Code Duplication
        if (!empty($searchData['order_date_end']) && $searchData['order_date_end']) {
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...
373 1
            $date = clone $searchData['order_date_end'];
374
            $date = $date
375 1
                ->modify('+1 days')
376 1
                ->format('Y-m-d H:i:s');
377
            $qb
378 1
                ->andWhere('o.order_date < :order_date_end')
379 1
                ->setParameter('order_date_end', $date);
380
        }
381
382
        // payment_date
383 32 View Code Duplication
        if (!empty($searchData['payment_date_start']) && $searchData['payment_date_start']) {
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...
384 1
            $date = $searchData['payment_date_start']
385 1
                ->format('Y-m-d H:i:s');
386
            $qb
387 1
                ->andWhere('o.payment_date >= :payment_date_start')
388 1
                ->setParameter('payment_date_start', $date);
389
        }
390 32 View Code Duplication
        if (!empty($searchData['payment_date_end']) && $searchData['payment_date_end']) {
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...
391 1
            $date = clone $searchData['payment_date_end'];
392
            $date = $date
393 1
                ->modify('+1 days')
394 1
                ->format('Y-m-d H:i:s');
395
            $qb
396 1
                ->andWhere('o.payment_date < :payment_date_end')
397 1
                ->setParameter('payment_date_end', $date);
398
        }
399
400
        // commit_date
401 32 View Code Duplication
        if (!empty($searchData['commit_date_start']) && $searchData['commit_date_start']) {
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...
402 1
            $date = $searchData['commit_date_start']
403 1
                ->format('Y-m-d H:i:s');
404
            $qb
405 1
                ->andWhere('o.commit_date >= :commit_date_start')
406 1
                ->setParameter('commit_date_start', $date);
407
        }
408 32 View Code Duplication
        if (!empty($searchData['commit_date_end']) && $searchData['commit_date_end']) {
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...
409 1
            $date = clone $searchData['commit_date_end'];
410
            $date = $date
411 1
                ->modify('+1 days')
412 1
                ->format('Y-m-d H:i:s');
413
            $qb
414 1
                ->andWhere('o.commit_date < :commit_date_end')
415 1
                ->setParameter('commit_date_end', $date);
416
        }
417
418
419
        // update_date
420 32 View Code Duplication
        if (!empty($searchData['update_date_start']) && $searchData['update_date_start']) {
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...
421 1
            $date = $searchData['update_date_start']
422 1
                ->format('Y-m-d H:i:s');
423
            $qb
424 1
                ->andWhere('o.update_date >= :update_date_start')
425 1
                ->setParameter('update_date_start', $date);
426
        }
427 32 View Code Duplication
        if (!empty($searchData['update_date_end']) && $searchData['update_date_end']) {
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...
428 1
            $date = clone $searchData['update_date_end'];
429
            $date = $date
430 1
                ->modify('+1 days')
431 1
                ->format('Y-m-d H:i:s');
432
            $qb
433 1
                ->andWhere('o.update_date < :update_date_end')
434 1
                ->setParameter('update_date_end', $date);
435
        }
436
437
        // payment_total
438 32 View Code Duplication
        if (isset($searchData['payment_total_start']) && Str::isNotBlank($searchData['payment_total_start'])) {
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...
439
            $qb
440 1
                ->andWhere('o.payment_total >= :payment_total_start')
441 1
                ->setParameter('payment_total_start', $searchData['payment_total_start']);
442
        }
443 32 View Code Duplication
        if (isset($searchData['payment_total_end']) && Str::isNotBlank($searchData['payment_total_end'])) {
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...
444
            $qb
445 1
                ->andWhere('o.payment_total <= :payment_total_end')
446 1
                ->setParameter('payment_total_end', $searchData['payment_total_end']);
447
        }
448
449
        // buy_product_name
450 32 View Code Duplication
        if (isset($searchData['buy_product_name']) && Str::isNotBlank($searchData['buy_product_name'])) {
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...
451
            $qb
452 1
                ->leftJoin('o.OrderDetails', 'od')
453 1
                ->andWhere('od.product_name LIKE :buy_product_name')
454 1
                ->setParameter('buy_product_name', '%' . $searchData['buy_product_name'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
455
        }
456
457
        // Order By
458 32
        $qb->orderBy('o.update_date', 'DESC');
459 32
        $qb->addorderBy('o.id', 'DESC');
460
461 32
        return $qb;
462
    }
463
464
465
    /**
466
     * @param  \Eccube\Entity\Customer $Customer
467
     * @return QueryBuilder
468
     */
469 3
    public function getQueryBuilderByCustomer(\Eccube\Entity\Customer $Customer)
470
    {
471 3
        $qb = $this->createQueryBuilder('o')
472 3
            ->where('o.Customer = :Customer')
473 3
            ->setParameter('Customer', $Customer);
474
475
        // Order By
476 3
        $qb->addOrderBy('o.id', 'DESC');
477
478 3
        return $qb;
479
    }
480
481
    /**
482
     * 新規受付一覧の取得
483
     *
484
     * @return \Eccube\Entity\Order[]
485
     */
486 1
    public function getNew()
487
    {
488 1
        $qb = $this->createQueryBuilder('o');
489
        $qb
490 1
            ->where('o.OrderStatus <> :OrderStatus')
491 1
            ->setParameter('OrderStatus', $this->app['config']['order_cancel'])
492 1
            ->setMaxResults(10)
493 1
            ->orderBy('o.create_date', 'DESC');
494
495
        return $qb
496 1
            ->getQuery()
497 1
            ->getResult();
498
    }
499
500
    /**
501
     * 会員の合計購入金額を取得、回数を取得
502
     *
503
     * @param  \Eccube\Entity\Customer $Customer
504
     * @param  array $OrderStatuses
0 ignored issues
show
introduced by
Expected 19 spaces after parameter type; 1 found
Loading history...
505
     * @return QueryBuilder
506
     */
507 14
    public function getCustomerCount(\Eccube\Entity\Customer $Customer, array $OrderStatuses)
508
    {
509 14
        $result = $this->createQueryBuilder('o')
510 14
            ->select('COUNT(o.id) AS buy_times, SUM(o.total)  AS buy_total')
511 14
            ->where('o.Customer = :Customer')
512 14
            ->andWhere('o.OrderStatus in (:OrderStatuses)')
513 14
            ->setParameter('Customer', $Customer)
514 14
            ->setParameter('OrderStatuses', $OrderStatuses)
515 14
            ->groupBy('o.id')
516 14
            ->orderBy('o.id', 'ASC')
517 14
            ->getQuery()
518 14
            ->getResult();
519
520 14
        return $result;
521
    }
522
}
523