CustomerRepository::loadUserByUsername()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 25
rs 8.8571
cc 2
eloc 18
nc 2
nop 1
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 Doctrine\ORM\EntityRepository;
28
use Eccube\Common\Constant;
29
use Eccube\Entity\Customer;
30
use Eccube\Entity\Master\CustomerStatus;
31
use Eccube\Util\Str;
32
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
33
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
34
use Symfony\Component\Security\Core\User\UserInterface;
35
use Symfony\Component\Security\Core\User\UserProviderInterface;
36
use Symfony\Component\Security\Core\Util\SecureRandom;
37
38
/**
39
 * CustomerRepository
40
 *
41
 * This class was generated by the Doctrine ORM. Add your own custom
42
 * repository methods below.
43
 */
44
class CustomerRepository extends EntityRepository implements UserProviderInterface
45
{
46
    protected $app;
47
48
    public function setApplication($app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
49
    {
50
        $this->app = $app;
51
    }
52
53
    public function newCustomer()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
54
    {
55
        $Customer = new \Eccube\Entity\Customer();
56
        $Status = $this->getEntityManager()
57
            ->getRepository('Eccube\Entity\Master\CustomerStatus')
58
            ->find(1);
59
60
        $Customer
61
            ->setStatus($Status)
62
            ->setDelFlg(0);
63
64
        return $Customer;
65
    }
66
67
    /**
68
     * Loads the user for the given username.
69
     *
70
     * This method must throw UsernameNotFoundException if the user is not
71
     * found.
72
     *
73
     * @param string $username The username
74
     *
75
     * @return UserInterface
76
     *
77
     * @see UsernameNotFoundException
78
     *
79
     * @throws UsernameNotFoundException if the user is not found
80
     */
81
    public function loadUserByUsername($username)
82
    {
83
        // 本会員ステータスの会員のみ有効.
84
        $CustomerStatus = $this
85
            ->getEntityManager()
86
            ->getRepository('Eccube\Entity\Master\CustomerStatus')
87
            ->find(CustomerStatus::ACTIVE);
88
89
        $query = $this->createQueryBuilder('c')
90
            ->where('c.email = :email')
91
            ->andWhere('c.del_flg = :delFlg')
92
            ->andWhere('c.Status =:CustomerStatus')
93
            ->setParameters(array(
94
                'email' => $username,
95
                'delFlg' => Constant::DISABLED,
96
                'CustomerStatus' => $CustomerStatus,
97
            ))
98
            ->getQuery();
99
        $Customer = $query->getOneOrNullResult();
100
        if (!$Customer) {
101
            throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
102
        }
103
104
        return $Customer;
105
    }
106
107
    /**
108
     * Refreshes the user for the account interface.
109
     *
110
     * It is up to the implementation to decide if the user data should be
111
     * totally reloaded (e.g. from the database), or if the UserInterface
112
     * object can just be merged into some internal array of users / identity
113
     * map.
114
     *
115
     * @param UserInterface $user
116
     *
117
     * @return UserInterface
118
     *
119
     * @throws UnsupportedUserException if the account is not supported
120
     */
121 View Code Duplication
    public function refreshUser(UserInterface $user)
0 ignored issues
show
Duplication introduced by
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...
122
    {
123
        if (!$user instanceof Customer) {
0 ignored issues
show
Bug introduced by
The class Eccube\Entity\Customer does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
124
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
125
        }
126
127
        return $this->loadUserByUsername($user->getUsername());
128
    }
129
130
    /**
131
     * Whether this provider supports the given user class.
132
     *
133
     * @param string $class
134
     *
135
     * @return bool
136
     */
137
    public function supportsClass($class)
138
    {
139
        return $class === 'Eccube\Entity\Customer';
140
    }
141
142
    public function getQueryBuilderBySearchData($searchData)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
143
    {
144
        $qb = $this->createQueryBuilder('c')
145
            ->select('c')
146
            ->andWhere('c.del_flg = 0');
147
148
        if (isset($searchData['multi']) && Str::isNotBlank($searchData['multi'])) {
149
            //スペース除去
150
            $clean_key_multi = preg_replace('/\s+|[ ]+/u', '',$searchData['multi']);
0 ignored issues
show
introduced by
Add a single space after each comma delimiter
Loading history...
151
            if (preg_match('/^\d+$/', $clean_key_multi)) {
152
                $qb
153
                    ->andWhere('c.id = :customer_id')
154
                    ->setParameter('customer_id', $clean_key_multi);
155
            } else {
156
                $qb
157
                    ->andWhere('CONCAT(c.name01, c.name02) LIKE :name OR CONCAT(c.kana01, c.kana02) LIKE :kana OR c.email LIKE :email')
158
                    ->setParameter('name', '%' . $clean_key_multi . '%')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
159
                    ->setParameter('kana', '%' . $clean_key_multi . '%')
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
160
                    ->setParameter('email', '%' . $clean_key_multi . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
161
            }
162
        }
163
164
        // Pref
165
        if (!empty($searchData['pref']) && $searchData['pref']) {
166
            $qb
167
                ->andWhere('c.Pref = :pref')
168
                ->setParameter('pref', $searchData['pref']->getId());
169
        }
170
171
        // sex
172
        if (!empty($searchData['sex']) && count($searchData['sex']) > 0) {
173
            $sexs = array();
174
            foreach ($searchData['sex'] as $sex) {
175
                $sexs[] = $sex->getId();
176
            }
177
178
            $qb
179
                ->andWhere($qb->expr()->in('c.Sex', ':sexs'))
180
                ->setParameter('sexs', $sexs);
181
        }
182
183
        // birth_month
184
        // TODO: http://docs.symfony.gr.jp/symfony2/cookbook/doctrine/custom_dql_functions.html
185
        if (!empty($searchData['birth_month']) && $searchData['birth_month']) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
186
//            $qb
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
187
//                ->andWhere('extract(month from c.birth) = :birth_month')
188
//                ->setParameter('birth_month', $searchData['birth_month']);
189
        }
190
191
        // birth
192 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...
193
            $date = $searchData['birth_start']
194
                ->format('Y-m-d H:i:s');
195
            $qb
196
                ->andWhere('c.birth >= :birth_start')
197
                ->setParameter('birth_start', $date);
198
        }
199 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...
200
            $date = clone $searchData['birth_end'];
201
            $date = $date
202
                ->modify('+1 days')
203
                ->format('Y-m-d H:i:s');
204
            $qb
205
                ->andWhere('c.birth < :birth_end')
206
                ->setParameter('birth_end', $date);
207
        }
208
209
        // tel
210 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...
211
            $qb
212
                ->andWhere('CONCAT(c.tel01, c.tel02, c.tel03) LIKE :tel')
213
                ->setParameter('tel', '%' . $searchData['tel'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
214
        }
215
216
        // buy_total
217 View Code Duplication
        if (isset($searchData['buy_total_start']) && Str::isNotBlank($searchData['buy_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...
218
            $qb
219
                ->andWhere('c.buy_total >= :buy_total_start')
220
                ->setParameter('buy_total_start', $searchData['buy_total_start']);
221
        }
222 View Code Duplication
        if (isset($searchData['buy_total_end']) && Str::isNotBlank($searchData['buy_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...
223
            $qb
224
                ->andWhere('c.buy_total <= :buy_total_end')
225
                ->setParameter('buy_total_end', $searchData['buy_total_end']);
226
        }
227
228
        // buy_times
229
        if (!empty($searchData['buy_times_start']) && $searchData['buy_times_start']) {
230
            $qb
231
                ->andWhere('c.buy_times >= :buy_times_start')
232
                ->setParameter('buy_times_start', $searchData['buy_times_start']);
233
        }
234
        if (!empty($searchData['buy_times_end']) && $searchData['buy_times_end']) {
235
            $qb
236
                ->andWhere('c.buy_times <= :buy_times_end')
237
                ->setParameter('buy_times_end', $searchData['buy_times_end']);
238
        }
239
240
        // create_date
241 View Code Duplication
        if (!empty($searchData['create_date_start']) && $searchData['create_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...
242
            $date = $searchData['create_date_start']
243
                ->format('Y-m-d H:i:s');
244
            $qb
245
                ->andWhere('c.create_date >= :create_date_start')
246
                ->setParameter('create_date_start', $date);
247
        }
248 View Code Duplication
        if (!empty($searchData['create_date_end']) && $searchData['create_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...
249
            $date = clone $searchData['create_date_end'];
250
            $date = $date
251
                ->modify('+1 days')
252
                ->format('Y-m-d H:i:s');
253
            $qb
254
                ->andWhere('c.create_date < :create_date_end')
255
                ->setParameter('create_date_end', $date);
256
        }
257
258
        // update_date
259 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...
260
            $date = $searchData['update_date_start']
261
                ->format('Y-m-d H:i:s');
262
            $qb
263
                ->andWhere('c.update_date >= :update_date_start')
264
                ->setParameter('update_date_start', $date);
265
        }
266 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...
267
            $date = clone $searchData['update_date_end'];
268
            $date = $date
269
                ->modify('+1 days')
270
                ->format('Y-m-d H:i:s');
271
            $qb
272
                ->andWhere('c.update_date < :update_date_end')
273
                ->setParameter('update_date_end', $date);
274
        }
275
276
        // last_buy
277 View Code Duplication
        if (!empty($searchData['last_buy_start']) && $searchData['last_buy_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...
278
            $date = $searchData['last_buy_start']
279
                ->format('Y-m-d H:i:s');
280
            $qb
281
                ->andWhere('c.last_buy_date >= :last_buy_start')
282
                ->setParameter('last_buy_start', $date);
283
        }
284 View Code Duplication
        if (!empty($searchData['last_buy_end']) && $searchData['last_buy_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...
285
            $date = clone $searchData['last_buy_end'];
286
            $date = $date
287
                ->modify('+1 days')
288
                ->format('Y-m-d H:i:s');
289
            $qb
290
                ->andWhere('c.last_buy_date < :last_buy_end')
291
                ->setParameter('last_buy_end', $date);
292
        }
293
294
        // status
295
        if (!empty($searchData['customer_status']) && count($searchData['customer_status']) > 0) {
296
            $qb
297
                ->andWhere($qb->expr()->in('c.Status', ':statuses'))
298
                ->setParameter('statuses', $searchData['customer_status']);
299
        }
300
301
        // buy_product_name、buy_product_code
302 View Code Duplication
        if (isset($searchData['buy_product_code']) && Str::isNotBlank($searchData['buy_product_code'])) {
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...
303
            $qb
304
                ->leftJoin('c.Orders', 'o')
305
                ->leftJoin('o.OrderDetails', 'od')
306
                ->andWhere('od.product_name LIKE :buy_product_name OR od.product_code LIKE :buy_product_name')
307
                ->setParameter('buy_product_name', '%' . $searchData['buy_product_code'] . '%');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
308
        }
309
310
        // Order By
311
        $qb->addOrderBy('c.update_date', 'DESC');
312
313
        return $qb;
314
    }
315
316
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
317
     * ユニークなシークレットキーを返す
318
     * @param $app
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
319
     * @return string
320
     */
321 View Code Duplication
    public function getUniqueSecretKey($app)
0 ignored issues
show
Duplication introduced by
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...
322
    {
323
        $unique = Str::random(32);
324
        $Customer = $app['eccube.repository.customer']->findBy(array(
325
            'secret_key' => $unique,
326
        ));
327
        if (count($Customer) == 0) {
328
            return $unique;
329
        } else {
330
            return $this->getUniqueSecretKey($app);
331
        }
332
    }
333
334
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
335
     * ユニークなパスワードリセットキーを返す
336
     * @param $app
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
337
     * @return string
338
     */
339 View Code Duplication
    public function getUniqueResetKey($app)
0 ignored issues
show
Duplication introduced by
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...
340
    {
341
        $unique = Str::random(32);
342
        $Customer = $app['eccube.repository.customer']->findBy(array(
343
                        'reset_key' => $unique,
344
        ));
345
        if (count($Customer) == 0) {
346
            return $unique;
347
        } else {
348
            return $this->getUniqueResetKey($app);
349
        }
350
    }
351
352
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$byte" missing
Loading history...
353
     * saltを生成する
354
     *
355
     * @param $byte
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
356
     * @return string
357
     */
358
    public function createSalt($byte)
359
    {
360
        $generator = new SecureRandom();
361
362
        return bin2hex($generator->nextBytes($byte));
363
    }
364
365
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
366
     * 入力されたパスワードをSaltと暗号化する
367
     *
368
     * @param $app
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
369
     * @param  Customer $Customer
370
     * @return mixed
371
     */
372
    public function encryptPassword($app, \Eccube\Entity\Customer $Customer)
373
    {
374
        $encoder = $app['security.encoder_factory']->getEncoder($Customer);
375
376
        return $encoder->encodePassword($Customer->getPassword(), $Customer->getSalt());
377
    }
378
379
    public function getNonActiveCustomerBySecretKey($secret_key)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
380
    {
381
        $qb = $this->createQueryBuilder('c')
382
            ->where('c.del_flg = 0 AND c.secret_key = :secret_key')
383
            ->leftJoin('c.Status', 's')
384
            ->andWhere('s.id = :status')
385
            ->setParameter('secret_key', $secret_key)
386
            ->setParameter('status', CustomerStatus::NONACTIVE);
387
        $query = $qb->getQuery();
388
389
        return $query->getSingleResult();
390
    }
391
392
    public function getActiveCustomerByEmail($email)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
393
    {
394
        $query = $this->createQueryBuilder('c')
395
            ->where('c.email = :email AND c.Status = :status')
396
            ->setParameter('email', $email)
397
            ->setParameter('status', CustomerStatus::ACTIVE)
398
            ->getQuery();
399
400
        $Customer = $query->getOneOrNullResult();
401
402
        return $Customer;
403
    }
404
405
    public function getActiveCustomerByResetKey($reset_key)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
406
    {
407
        $query = $this->createQueryBuilder('c')
408
            ->where('c.reset_key = :reset_key AND c.Status = :status AND c.reset_expire >= :reset_expire')
409
            ->setParameter('reset_key', $reset_key)
410
            ->setParameter('status', CustomerStatus::ACTIVE)
411
            ->setParameter('reset_expire', new \DateTime())
412
            ->getQuery();
413
414
        $Customer = $query->getSingleResult();
415
416
        return $Customer;
417
    }
418
419
    public function getResetPassword()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
420
    {
421
        return Str::random(8);
422
    }
423
424
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$app" missing
Loading history...
introduced by
Doc comment for parameter "$orderStatusId" missing
Loading history...
425
     * 会員の初回購入時間、購入時間、購入回数、購入金額を更新する
426
     *
427
     * @param $app
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
428
     * @param  Customer $Customer
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
429
     * @param  $orderStatusId
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
430
     */
431
    public function updateBuyData($app, Customer $Customer, $orderStatusId)
432
    {
433
        // 会員の場合、初回購入時間・購入時間・購入回数・購入金額を更新
434
435
        $arr = array($app['config']['order_new'],
436
                                $app['config']['order_pay_wait'],
437
                                $app['config']['order_back_order'],
438
                                $app['config']['order_deliv'],
439
                                $app['config']['order_pre_end'],
440
                        );
441
442
        $result = $app['eccube.repository.order']->getCustomerCount($Customer, $arr);
443
444
        if (!empty($result)) {
445
            $data = $result[0];
446
447
            $now = new \DateTime();
448
449
            $firstBuyDate = $Customer->getFirstBuyDate();
450
            if (empty($firstBuyDate)) {
451
                $Customer->setFirstBuyDate($now);
452
            }
453
454
            if ($orderStatusId == $app['config']['order_cancel'] ||
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
455
                    $orderStatusId == $app['config']['order_pending'] ||
456
                    $orderStatusId == $app['config']['order_processing']) {
457
                // キャンセル、決済処理中、購入処理中は購入時間は更新しない
458
            } else {
459
                $Customer->setLastBuyDate($now);
460
            }
461
462
            $Customer->setBuyTimes($data['buy_times']);
463
            $Customer->setBuyTotal($data['buy_total']);
464
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
465
        } else {
466
            // 受注データが存在しなければ初期化
467
            $Customer->setFirstBuyDate(null);
468
            $Customer->setLastBuyDate(null);
469
            $Customer->setBuyTimes(0);
470
            $Customer->setBuyTotal(0);
471
        }
472
473
        $app['orm.em']->persist($Customer);
474
        $app['orm.em']->flush();
475
    }
476
}
477