Failed Conditions
Pull Request — experimental/sf (#29)
by Kentaro
50:12 queued 39:05
created

ShippingRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.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\ORM\QueryBuilder;
17
use Eccube\Entity\Shipping;
18
use Eccube\Util\StringUtil;
19
use Symfony\Bridge\Doctrine\RegistryInterface;
20
21
/**
22
 * ShippingRepository
23
 *
24
 * This class was generated by the Doctrine ORM. Add your own custom
25
 * repository methods below.
26
 */
27
class ShippingRepository extends AbstractRepository
28
{
29 116
    public function __construct(RegistryInterface $registry)
30
    {
31 116
        parent::__construct($registry, Shipping::class);
32
    }
33
34
    /**
35
     * Build query
36
     *
37
     * @param  array $searchData
38
     *
39
     * @return QueryBuilder
40
     */
41
    public function getQueryBuilderBySearchDataForAdmin($searchData)
42
    {
43
        $qb = $this->createQueryBuilder('s');
44
45
        $qb->leftJoin('s.OrderItems', 'si')
46
            ->leftJoin('si.Order', 'o');
47
        // order_id_start
48 View Code Duplication
        if (isset($searchData['shipping_id_start']) && StringUtil::isNotBlank($searchData['shipping_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...
49
            $qb
50
                ->andWhere('s.id >= :shipping_id_start')
51
                ->setParameter('shipping_id_start', $searchData['shipping_id_start']);
52
        }
53
        // multi
54 View Code Duplication
        if (isset($searchData['multi']) && StringUtil::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...
55
            $multi = preg_match('/^\d{0,10}$/', $searchData['multi']) ? $searchData['multi'] : null;
56
            $qb
57
                ->andWhere('s.id = :multi OR s.name01 LIKE :likemulti OR s.name02 LIKE :likemulti OR '.
58
                            's.kana01 LIKE :likemulti OR s.kana02 LIKE :likemulti OR s.company_name LIKE :likemulti')
59
                ->setParameter('multi', $multi)
60
                ->setParameter('likemulti', '%'.$searchData['multi'].'%');
61
        }
62
63
        // shipping_id_end
64 View Code Duplication
        if (isset($searchData['shipping_id_end']) && StringUtil::isNotBlank($searchData['shipping_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...
65
            $qb
66
                ->andWhere('s.id <= :shipping_id_end')
67
                ->setParameter('shipping_id_end', $searchData['shipping_id_end']);
68
        }
69
70
        // order_id
71 View Code Duplication
        if (isset($searchData['order_id']) && StringUtil::isNotBlank($searchData['order_id'])) {
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...
72
            $qb
73
                ->andWhere('o.id = :order_id')
74
                ->setParameter('order_id', $searchData['order_id']);
75
        }
76
77
        // order_no
78 View Code Duplication
        if (isset($searchData['order_no']) && StringUtil::isNotBlank($searchData['order_no'])) {
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...
79
            $qb
80
                ->andWhere('o.order_no LIKE :order_no')
81
                ->setParameter('order_no', "%{$searchData['order_no']}%");
82
        }
83
84
        // order status
85
        if (isset($searchData['order_status']) && count($searchData['order_status'])) {
86
            $s = $searchData['order_status'];
0 ignored issues
show
Unused Code introduced by
$s 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...
87
            $qb
88
                ->andWhere($qb->expr()->in('o.OrderStatus', ':order_status'))
89
                ->setParameter('order_status', $searchData['order_status']);
90
        }
91
        // name
92 View Code Duplication
        if (isset($searchData['name']) && StringUtil::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...
93
            $qb
94
                ->andWhere('CONCAT(s.name01, s.name02) LIKE :name')
95
                ->setParameter('name', '%'.$searchData['name'].'%');
96
        }
97
98
        // kana
99 View Code Duplication
        if (isset($searchData['kana']) && StringUtil::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...
100
            $qb
101
                ->andWhere('CONCAT(s.kana01, s.kana02) LIKE :kana')
102
                ->setParameter('kana', '%'.$searchData['kana'].'%');
103
        }
104
105
        // order_name
106 View Code Duplication
        if (isset($searchData['order_name']) && StringUtil::isNotBlank($searchData['order_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...
107
            $qb
108
                ->andWhere('CONCAT(o.name01, o.name02) LIKE :order_name')
109
                ->setParameter('order_name', '%'.$searchData['order_name'].'%');
110
        }
111
112
        // order_kana
113 View Code Duplication
        if (isset($searchData['order_kana']) && StringUtil::isNotBlank($searchData['order_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...
114
            $qb
115
                ->andWhere('CONCAT(o.kana01, s.kana02) LIKE :order_kana')
116
                ->setParameter('order_kana', '%'.$searchData['order_kana'].'%');
117
        }
118
119
        // order_email
120 View Code Duplication
        if (isset($searchData['email']) && StringUtil::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...
121
            $qb
122
                ->andWhere('o.email like :email')
123
                ->setParameter('email', '%'.$searchData['email'].'%');
124
        }
125
126
        // tel
127 View Code Duplication
        if (isset($searchData['phone_number']) && StringUtil::isNotBlank($searchData['phone_number'])) {
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...
128
            $tel = preg_replace('/[^0-9]/ ', '', $searchData['phone_number']);
129
            $qb
130
                ->andWhere('s.phone_number LIKE :phone_number')
131
                ->setParameter('phone_number', '%'.$tel.'%');
132
        }
133
134
        // payment
135 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...
136
            $payments = [];
137
            foreach ($searchData['payment'] as $payment) {
138
                $payments[] = $payment->getId();
139
            }
140
            $qb
141
                ->leftJoin('o.Payment', 'p')
142
                ->andWhere($qb->expr()->in('p.id', ':payments'))
143
                ->setParameter('payments', $payments);
144
        }
145
146
        // oreder_date
147 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...
148
            $date = $searchData['order_date_start'];
149
            $qb
150
                ->andWhere('o.order_date >= :order_date_start')
151
                ->setParameter('order_date_start', $date);
152
        }
153 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...
154
            $date = clone $searchData['order_date_end'];
155
            $date = $date
156
                ->modify('+1 days');
157
            $qb
158
                ->andWhere('o.order_date < :order_date_end')
159
                ->setParameter('order_date_end', $date);
160
        }
161
162
        // shipping_delivery_date
163 View Code Duplication
        if (!empty($searchData['shipping_delivery_date_start']) && $searchData['shipping_delivery_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...
164
            $date = $searchData['shipping_delivery_date_start'];
165
            $qb
166
                ->andWhere('s.shipping_delivery_date >= :shipping_delivery_date_start')
167
                ->setParameter('shipping_delivery_date_start', $date);
168
        }
169 View Code Duplication
        if (!empty($searchData['shipping_delivery_date_end']) && $searchData['shipping_delivery_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...
170
            $date = clone $searchData['shipping_delivery_date_end'];
171
            $date = $date
172
                ->modify('+1 days');
173
            $qb
174
                ->andWhere('s.shipping_delivery_date < :shipping_delivery_date_end')
175
                ->setParameter('shipping_delivery_date_end', $date);
176
        }
177
178
        // shipping_date
179 View Code Duplication
        if (!empty($searchData['shipping_date_start']) && $searchData['shipping_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...
180
            $date = $searchData['shipping_date_start'];
181
            $qb
182
                ->andWhere('s.shipping_date >= :shipping_date_start')
183
                ->setParameter('shipping_date_start', $date);
184
        }
185 View Code Duplication
        if (!empty($searchData['shipping_date_end']) && $searchData['shipping_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...
186
            $date = clone $searchData['shipping_date_end'];
187
            $date = $date
188
                ->modify('+1 days');
189
            $qb
190
                ->andWhere('s.shipping_date < :shipping_date_end')
191
                ->setParameter('shipping_date_end', $date);
192
        }
193
194
        // update_date
195 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...
196
            $date = $searchData['update_date_start'];
197
            $qb
198
                ->andWhere('s.update_date >= :update_date_start')
199
                ->setParameter('update_date_start', $date);
200
        }
201 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...
202
            $date = clone $searchData['update_date_end'];
203
            $date = $date
204
                ->modify('+1 days');
205
            $qb
206
                ->andWhere('s.update_date < :update_date_end')
207
                ->setParameter('update_date_end', $date);
208
        }
209
210
        // payment_total
211 View Code Duplication
        if (isset($searchData['payment_total_start']) && StringUtil::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...
212
            $qb
213
                ->andWhere('o.payment_total >= :payment_total_start')
214
                ->setParameter('payment_total_start', $searchData['payment_total_start']);
215
        }
216 View Code Duplication
        if (isset($searchData['payment_total_end']) && StringUtil::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...
217
            $qb
218
                ->andWhere('o.payment_total <= :payment_total_end')
219
                ->setParameter('payment_total_end', $searchData['payment_total_end']);
220
        }
221
222
        // buy_product_name
223 View Code Duplication
        if (isset($searchData['buy_product_name']) && StringUtil::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...
224
            $qb
225
                ->andWhere('si.product_name LIKE :buy_product_name')
226
                ->setParameter('buy_product_name', '%'.$searchData['buy_product_name'].'%');
227
        }
228
229
        // Order By
230
        $qb->orderBy('s.update_date', 'DESC');
231
        $qb->addorderBy('s.id', 'DESC');
232
233
        return $qb;
234
    }
235
236
    /**
237
     * 同一商品のお届け先情報を取得
238
     *
239
     * @param \Eccube\Entity\Order|null $Order
240
     * @param \Eccube\Entity\ProductClass|null $productClass
241
     *
242
     * @return array
243
     */
244 27
    public function findShippingsProduct($Order, $productClass)
245
    {
246 27
        $shippings = $this->createQueryBuilder('s')
247 27
            ->innerJoin('Eccube\Entity\OrderItem', 'si', 'WITH', 'si.Shipping = s.id')
248 27
            ->where('si.Order = (:order)')
249 27
            ->andWhere('si.ProductClass = (:productClass)')
250 27
            ->setParameter('order', $Order)
251 27
            ->setParameter('productClass', $productClass)
252 27
            ->getQuery()
253 27
            ->getResult();
254
255 27
        return $shippings;
256
    }
257
}
258