Conditions | 46 |
Paths | > 20000 |
Total Lines | 183 |
Code Lines | 120 |
Lines | 124 |
Ratio | 67.76 % |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
72 | public function getQueryBuilderBySearchData($searchData) |
||
73 | { |
||
74 | $qb = $this->createQueryBuilder('o'); |
||
75 | |||
76 | $joinedCustomer = false; |
||
77 | |||
78 | // order_id_start |
||
79 | View Code Duplication | if (isset($searchData['order_id_start']) && Str::isNotBlank($searchData['order_id_start'])) { |
|
80 | $qb |
||
81 | ->andWhere('o.id >= :order_id_start') |
||
82 | ->setParameter('order_id_start', $searchData['order_id_start']); |
||
83 | } |
||
84 | |||
85 | // order_id_end |
||
86 | View Code Duplication | if (isset($searchData['order_id_end']) && Str::isNotBlank($searchData['order_id_end'])) { |
|
87 | $qb |
||
88 | ->andWhere('o.id <= :order_id_end') |
||
89 | ->setParameter('order_id_end', $searchData['order_id_end']); |
||
90 | } |
||
91 | |||
92 | // status |
||
93 | if (!empty($searchData['status']) && $searchData['status']) { |
||
94 | $qb |
||
95 | ->andWhere('o.OrderStatus = :status') |
||
96 | ->setParameter('status', $searchData['status']); |
||
97 | } |
||
98 | |||
99 | // name |
||
100 | View Code Duplication | if (isset($searchData['name']) && Str::isNotBlank($searchData['name'])) { |
|
101 | $qb |
||
102 | ->andWhere('CONCAT(o.name01, o.name02) LIKE :name') |
||
103 | ->setParameter('name', '%' . $searchData['name'] . '%'); |
||
104 | } |
||
105 | |||
106 | // kana |
||
107 | View Code Duplication | if (isset($searchData['kana']) && Str::isNotBlank($searchData['kana'])) { |
|
108 | $qb |
||
109 | ->andWhere('CONCAT(o.kana01, o.kana02) LIKE :kana') |
||
110 | ->setParameter('kana', '%' . $searchData['kana'] . '%'); |
||
111 | } |
||
112 | |||
113 | |||
114 | View Code Duplication | if (isset($searchData['email']) && Str::isNotBlank($searchData['email'])) { |
|
115 | $qb |
||
116 | ->andWhere('o.email = :email') |
||
117 | ->setParameter('email', $searchData['email']); |
||
118 | } |
||
119 | |||
120 | // tel |
||
121 | View Code Duplication | if (isset($searchData['tel01']) && Str::isNotBlank($searchData['tel01'])) { |
|
122 | $qb |
||
123 | ->andWhere('o.tel01 = :tel01') |
||
124 | ->setParameter('tel01', $searchData['tel01']); |
||
125 | } |
||
126 | View Code Duplication | if (isset($searchData['tel02']) && Str::isNotBlank($searchData['tel02'])) { |
|
127 | $qb |
||
128 | ->andWhere('o.tel02 = :tel02') |
||
129 | ->setParameter('tel02', $searchData['tel02']); |
||
130 | } |
||
131 | View Code Duplication | if (isset($searchData['tel03']) && Str::isNotBlank($searchData['tel03'])) { |
|
132 | $qb |
||
133 | ->andWhere('o.tel03 = :tel03') |
||
134 | ->setParameter('tel03', $searchData['tel03']); |
||
135 | } |
||
136 | |||
137 | // birth |
||
138 | View Code Duplication | if (!empty($searchData['birth_start']) && $searchData['birth_start']) { |
|
139 | if (!$joinedCustomer) { |
||
140 | $qb->leftJoin('o.Customer', 'c'); |
||
141 | $joinedCustomer = true; |
||
142 | } |
||
143 | |||
144 | $date = $searchData['birth_start'] |
||
145 | ->format('Y-m-d H:i:s'); |
||
146 | $qb |
||
147 | ->andWhere('c.birth >= :birth_start') |
||
148 | ->setParameter('birth_start', $date); |
||
149 | } |
||
150 | View Code Duplication | if (!empty($searchData['birth_end']) && $searchData['birth_end']) { |
|
151 | if (!$joinedCustomer) { |
||
152 | $qb->leftJoin('o.Customer', 'c'); |
||
153 | $joinedCustomer = true; |
||
154 | } |
||
155 | |||
156 | $date = clone $searchData['birth_end']; |
||
157 | $date = $date |
||
158 | ->modify('+1 days') |
||
159 | ->format('Y-m-d H:i:s'); |
||
160 | $qb |
||
161 | ->andWhere('c.birth < :birth_end') |
||
162 | ->setParameter('birth_end', $date); |
||
163 | } |
||
164 | |||
165 | // sex |
||
166 | if (!empty($searchData['sex']) && count($searchData['sex']) > 0) { |
||
167 | if (!$joinedCustomer) { |
||
168 | $qb->leftJoin('o.Customer', 'c'); |
||
169 | $joinedCustomer = true; |
||
170 | } |
||
171 | |||
172 | $sexs = array(); |
||
173 | foreach ($searchData['sex'] as $sex) { |
||
174 | $sexs[] = $sex->getId(); |
||
175 | } |
||
176 | |||
177 | $qb |
||
178 | ->andWhere($qb->expr()->in('c.Sex', ':sexs')) |
||
179 | ->setParameter('sexs', $sexs); |
||
180 | } |
||
181 | |||
182 | // payment |
||
183 | View Code Duplication | if (!empty($searchData['payment']) && count($searchData['payment'])) { |
|
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 | View Code Duplication | if (!empty($searchData['order_date_start']) && $searchData['order_date_start']) { |
|
196 | $date = $searchData['order_date_start'] |
||
197 | ->format('Y-m-d H:i:s'); |
||
198 | $qb |
||
199 | ->andWhere('o.create_date >= :order_date_start') |
||
200 | ->setParameter('order_date_start', $date); |
||
201 | } |
||
202 | View Code Duplication | if (!empty($searchData['order_date_end']) && $searchData['order_date_end']) { |
|
203 | $date = clone $searchData['order_date_end']; |
||
204 | $date = $date |
||
205 | ->modify('+1 days') |
||
206 | ->format('Y-m-d H:i:s'); |
||
207 | $qb |
||
208 | ->andWhere('o.create_date < :order_date_end') |
||
209 | ->setParameter('order_date_end', $date); |
||
210 | } |
||
211 | |||
212 | // create_date |
||
213 | View Code Duplication | if (!empty($searchData['update_date_start']) && $searchData['update_date_start']) { |
|
214 | $date = $searchData['update_date_start'] |
||
215 | ->format('Y-m-d H:i:s'); |
||
216 | $qb |
||
217 | ->andWhere('o.update_date >= :update_date_start') |
||
218 | ->setParameter('update_date_start', $date); |
||
219 | } |
||
220 | View Code Duplication | if (!empty($searchData['update_date_end']) && $searchData['update_date_end']) { |
|
221 | $date = clone $searchData['update_date_end']; |
||
222 | $date = $date |
||
223 | ->modify('+1 days') |
||
224 | ->format('Y-m-d H:i:s'); |
||
225 | $qb |
||
226 | ->andWhere('o.update_date < :update_date_end') |
||
227 | ->setParameter('update_date_end', $date); |
||
228 | } |
||
229 | |||
230 | // payment_total |
||
231 | View Code Duplication | if (isset($searchData['payment_total_start']) && Str::isNotBlank($searchData['payment_total_start'])) { |
|
232 | $qb |
||
233 | ->andWhere('o.payment_total >= :payment_total_start') |
||
234 | ->setParameter('payment_total_start', $searchData['payment_total_start']); |
||
235 | } |
||
236 | View Code Duplication | if (isset($searchData['payment_total_end']) && Str::isNotBlank($searchData['payment_total_end'])) { |
|
237 | $qb |
||
238 | ->andWhere('o.payment_total <= :payment_total_end') |
||
239 | ->setParameter('payment_total_end', $searchData['payment_total_end']); |
||
240 | } |
||
241 | |||
242 | // buy_product_name |
||
243 | View Code Duplication | if (isset($searchData['buy_product_name']) && Str::isNotBlank($searchData['buy_product_name'])) { |
|
244 | $qb |
||
245 | ->leftJoin('o.OrderDetails', 'od') |
||
246 | ->andWhere('od.product_name LIKE :buy_product_name') |
||
247 | ->setParameter('buy_product_name', '%' . $searchData['buy_product_name'] . '%'); |
||
248 | } |
||
249 | |||
250 | // Order By |
||
251 | $qb->addOrderBy('o.update_date', 'DESC'); |
||
252 | |||
253 | return $qb; |
||
254 | } |
||
255 | |||
506 |