PaymentRepository::findPayments()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
nc 2
nop 2
dl 0
loc 20
ccs 12
cts 12
cp 1
crap 2
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 */
24
25
namespace Eccube\Repository;
26
27
use Doctrine\ORM\EntityRepository;
28
use Doctrine\ORM\Query;
29
30
/**
31
 * PaymentRepository
32
 *
33
 * This class was generated by the Doctrine ORM. Add your own custom
34
 * repository methods below.
35
 */
36
class PaymentRepository extends EntityRepository
37
{
38
39 11
    public function findOrCreate($id)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
40
    {
41 11
        if ($id == 0) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
42
43 8
            $Payment = $this->findOneBy(array(), array('rank' => 'DESC'));
44
45 8
            $rank = 1;
46 8
            if ($Payment) {
47 8
                $rank = $Payment->getRank() + 1;
48
            }
49
50 8
            $Payment = new \Eccube\Entity\Payment();
51
            $Payment
52 8
                ->setRank($rank)
53 8
                ->setDelFlg(0)
54 8
                ->setFixFlg(1)
55 8
                ->setChargeFlg(1);
56
        } else {
57 3
            $Payment = $this->find($id);
58
        }
59
60 11
        return $Payment;
61
    }
62
63 1
    public function findAllArray()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
64
    {
65
66
        $query = $this
67 1
            ->getEntityManager()
68 1
            ->createQuery('SELECT p FROM Eccube\Entity\Payment p INDEX BY p.id');
69
        $result = $query
70 1
            ->getResult(Query::HYDRATE_ARRAY);
71
72 1
        return $result;
73
    }
74
75
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$delivery" missing
Loading history...
introduced by
Doc comment for parameter "$returnType" missing
Loading history...
76
     * 支払方法を取得
77
     * 条件によってはDoctrineのキャッシュが返されるため、arrayで結果を返すパターンも用意
78
     *
79
     * @param $delivery
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
80
     * @param $returnType true : Object、false: arrayが戻り値
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
81
     * @return array
82
     */
83 111
    public function findPayments($delivery, $returnType = false)
84
    {
85
86 111
        $query = $this->createQueryBuilder('p')
87 111
            ->innerJoin('Eccube\Entity\PaymentOption', 'po', 'WITH', 'po.payment_id = p.id')
88 111
            ->where('po.Delivery = (:delivery)')
89 111
            ->orderBy('p.rank', 'DESC')
90 111
            ->setParameter('delivery', $delivery)
91 111
            ->getQuery();
92
93 111
        $query->expireResultCache(false);
94
95 111
        if ($returnType) {
96 83
            $payments = $query->getResult();
97
        } else {
98 108
            $payments = $query->getArrayResult();
99
        }
100
101 111
        return $payments;
102
    }
103
104
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$deliveries" missing
Loading history...
105
     * 共通の支払方法を取得
106
     *
107
     * @param $deliveries
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
108
     * @return array
109
     */
110 108
    public function findAllowedPayments($deliveries)
111
    {
112 108
        $payments = array();
113 108
        $i = 0;
114
115 108
        foreach ($deliveries as $Delivery) {
116 107
            $p = $this->findPayments($Delivery);
117
118 107
            if ($i != 0) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
119
120 10
                $arr = array();
121 10
                foreach ($p as $payment) {
122 10
                    foreach ($payments as $pay) {
123 10
                        if ($payment['id'] == $pay['id']) {
124 8
                            $arr[] = $payment;
125 10
                            break;
126
                        }
127
                    }
128
                }
129
130 10
                $payments = $arr;
131
            } else {
132 107
                $payments = $p;
133
            }
134 108
            $i++;
135
        }
136
137 108
        return $payments;
138
    }
139
}
140