Failed Conditions
Push — experimental/3.1 ( 0c67c0...62371a )
by chihiro
51:52
created

getQueryBuilderBySearchDataForAdmin()   F

Complexity

Conditions 43
Paths > 20000

Size

Total Lines 165
Code Lines 109

Duplication

Lines 125
Ratio 75.76 %

Code Coverage

Tests 11
CRAP Score 43

Importance

Changes 0
Metric Value
cc 43
eloc 109
nc 1572864
nop 1
dl 125
loc 165
ccs 11
cts 11
cp 1
crap 43
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
29
/**
30
 * ShippingRepository
31
 *
32
 * This class was generated by the Doctrine ORM. Add your own custom
33
 * repository methods below.
34
 */
35
class ShippingRepository extends AbstractRepository
36
{
37
    /**
38
     *
39
     * @param  array        $searchData
0 ignored issues
show
introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
40
     * @return QueryBuilder
41
     */
42
    public function getQueryBuilderBySearchDataForAdmin($searchData)
43
    {
44 1
        $qb = $this->createQueryBuilder('o');
45
46 1
        // order_id_start
47 1 View Code Duplication
        if (isset($searchData['order_id_start']) && Str::isNotBlank($searchData['order_id_start'])) {
48 1
            $qb
49 1
                ->andWhere('o.id >= :order_id_start')
50 1
                ->setParameter('order_id_start', $searchData['order_id_start']);
51 1
        }
52 1
        // multi
53 1 View Code Duplication
        if (isset( $searchData['multi']) && Str::isNotBlank($searchData['multi'])) {
54 1
            $multi = preg_match('/^\d+$/', $searchData['multi']) ? $searchData['multi'] : null;
55
            $qb
56 1
                ->andWhere('o.id = :multi OR 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...
57
                           '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 16 spaces, but found 27.
Loading history...
58
                ->setParameter('multi', $multi)
59
                ->setParameter('likemulti', '%' . $searchData['multi'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
60
        }
61
62
        // order_id_end
63 View Code Duplication
        if (isset($searchData['order_id_end']) && Str::isNotBlank($searchData['order_id_end'])) {
64
            $qb
65
                ->andWhere('o.id <= :order_id_end')
66
                ->setParameter('order_id_end', $searchData['order_id_end']);
67
        }
68
69
        // name
70 View Code Duplication
        if (isset($searchData['name']) && Str::isNotBlank($searchData['name'])) {
71
            $qb
72
                ->andWhere('CONCAT(o.name01, o.name02) LIKE :name')
73
                ->setParameter('name', '%' . $searchData['name'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
74
        }
75
76
        // kana
77 View Code Duplication
        if (isset($searchData['kana']) && Str::isNotBlank($searchData['kana'])) {
78
            $qb
79
                ->andWhere('CONCAT(o.kana01, o.kana02) LIKE :kana')
80
                ->setParameter('kana', '%' . $searchData['kana'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
81
        }
82
83
        // email
84 View Code Duplication
        if (isset($searchData['email']) && Str::isNotBlank($searchData['email'])) {
85
            $qb
86
                ->andWhere('o.email like :email')
87
                ->setParameter('email', '%' . $searchData['email'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
88
        }
89
90
        // tel
91 View Code Duplication
        if (isset($searchData['tel']) && Str::isNotBlank($searchData['tel'])) {
92
            $qb
93
                ->andWhere('CONCAT(o.tel01, o.tel02, o.tel03) LIKE :tel')
94
                ->setParameter('tel', '%' . $searchData['tel'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
95
        }
96
97
        // sex
98 View Code Duplication
        if (!empty($searchData['sex']) && count($searchData['sex']) > 0) {
99
            $qb
100
                ->andWhere($qb->expr()->in('o.Sex', ':sex'))
101
                ->setParameter('sex', $searchData['sex']->toArray());
102
        }
103
104
        // payment
105 View Code Duplication
        if (!empty($searchData['payment']) && count($searchData['payment'])) {
106
            $payments = array();
107
            foreach ($searchData['payment'] as $payment) {
108
                $payments[] = $payment->getId();
109
            }
110
            $qb
111
                ->leftJoin('o.Payment', 'p')
112
                ->andWhere($qb->expr()->in('p.id', ':payments'))
113
                ->setParameter('payments', $payments);
114
        }
115
116
        // oreder_date
117 View Code Duplication
        if (!empty($searchData['order_date_start']) && $searchData['order_date_start']) {
118
            $date = $searchData['order_date_start'];
119
            $qb
120
                ->andWhere('o.order_date >= :order_date_start')
121
                ->setParameter('order_date_start', $date);
122
        }
123 View Code Duplication
        if (!empty($searchData['order_date_end']) && $searchData['order_date_end']) {
124
            $date = clone $searchData['order_date_end'];
125
            $date = $date
126
                ->modify('+1 days');
127
            $qb
128
                ->andWhere('o.order_date < :order_date_end')
129
                ->setParameter('order_date_end', $date);
130
        }
131
132
        // payment_date
133 View Code Duplication
        if (!empty($searchData['payment_date_start']) && $searchData['payment_date_start']) {
134
            $date = $searchData['payment_date_start'];
135
            $qb
136
                ->andWhere('o.payment_date >= :payment_date_start')
137
                ->setParameter('payment_date_start', $date);
138
        }
139 View Code Duplication
        if (!empty($searchData['payment_date_end']) && $searchData['payment_date_end']) {
140
            $date = clone $searchData['payment_date_end'];
141
            $date = $date
142
                ->modify('+1 days');
143
            $qb
144
                ->andWhere('o.payment_date < :payment_date_end')
145
                ->setParameter('payment_date_end', $date);
146
        }
147
148
        // commit_date
149 View Code Duplication
        if (!empty($searchData['commit_date_start']) && $searchData['commit_date_start']) {
150
            $date = $searchData['commit_date_start'];
151
            $qb
152
                ->andWhere('o.commit_date >= :commit_date_start')
153
                ->setParameter('commit_date_start', $date);
154
        }
155 View Code Duplication
        if (!empty($searchData['commit_date_end']) && $searchData['commit_date_end']) {
156
            $date = clone $searchData['commit_date_end'];
157
            $date = $date
158
                ->modify('+1 days');
159
            $qb
160
                ->andWhere('o.commit_date < :commit_date_end')
161
                ->setParameter('commit_date_end', $date);
162
        }
163
164
165
        // update_date
166 View Code Duplication
        if (!empty($searchData['update_date_start']) && $searchData['update_date_start']) {
167
            $date = $searchData['update_date_start'];
168
            $qb
169
                ->andWhere('o.update_date >= :update_date_start')
170
                ->setParameter('update_date_start', $date);
171
        }
172 View Code Duplication
        if (!empty($searchData['update_date_end']) && $searchData['update_date_end']) {
173
            $date = clone $searchData['update_date_end'];
174
            $date = $date
175
                ->modify('+1 days');
176
            $qb
177
                ->andWhere('o.update_date < :update_date_end')
178
                ->setParameter('update_date_end', $date);
179
        }
180
181
        // payment_total
182 View Code Duplication
        if (isset($searchData['payment_total_start']) && Str::isNotBlank($searchData['payment_total_start'])) {
183
            $qb
184
                ->andWhere('o.payment_total >= :payment_total_start')
185
                ->setParameter('payment_total_start', $searchData['payment_total_start']);
186
        }
187 View Code Duplication
        if (isset($searchData['payment_total_end']) && Str::isNotBlank($searchData['payment_total_end'])) {
188
            $qb
189
                ->andWhere('o.payment_total <= :payment_total_end')
190
                ->setParameter('payment_total_end', $searchData['payment_total_end']);
191
        }
192
193
        // buy_product_name
194 View Code Duplication
        if (isset($searchData['buy_product_name']) && Str::isNotBlank($searchData['buy_product_name'])) {
195
            $qb
196
                ->leftJoin('o.OrderDetails', 'od')
197
                ->andWhere('od.product_name LIKE :buy_product_name')
198
                ->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...
199
        }
200
201
        // Order By
202
        $qb->orderBy('o.update_date', 'DESC');
203
        $qb->addorderBy('o.id', 'DESC');
204
205
        return $qb;
206
    }
207
208
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Order" missing
Loading history...
introduced by
Doc comment for parameter "$productClass" missing
Loading history...
209
     * 同一商品のお届け先情報を取得
210
     *
211
     * @param $Order
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
212
     * @return array
213
     */
214
    public function findShippingsProduct($Order, $productClass)
215
    {
216
        $shippings = $this->createQueryBuilder('s')
217
            ->innerJoin('Eccube\Entity\ShipmentItem', 'si', 'WITH', 'si.Shipping = s.id')
218
            ->where('si.Order = (:order)')
219
            ->andWhere('si.ProductClass = (:productClass)')
220
            ->setParameter('order', $Order)
221
            ->setParameter('productClass', $productClass)
222
            ->getQuery()
223
            ->getResult();
224
225
        return $shippings;
226
227
    }
228
229
}
230