Failed Conditions
Pull Request — experimental/3.1 (#2159)
by Kentaro
39:20
created

PaymentRepository::findAllArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
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 11
39
    public function findOrCreate($id)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
40 11
    {
41
        if ($id == 0) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
42 8
43 8
            $Payment = $this->findOneBy(array(), array('rank' => 'DESC'));
44 8
45
            $rank = 1;
46 8
            if ($Payment) {
47
                $rank = $Payment->getRank() + 1;
48 8
            }
49 8
50 8
            $Payment = new \Eccube\Entity\Payment();
51
            $Payment
52
                ->setRank($rank)
53 8
                ->setDelFlg(0)
54
                ->setFixFlg(1)
55 8
                ->setChargeFlg(1);
56 8
        } else {
57 8
            $Payment = $this->find($id);
58 8
        }
59 8
60
        return $Payment;
61
    }
62 3
63
    public function findAllArray()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
64
    {
65
66 11
        $query = $this
67
            ->getEntityManager()
68
            ->createQuery('SELECT p FROM Eccube\Entity\Payment p INDEX BY p.id');
69 1
        $result = $query
70
            ->getResult(Query::HYDRATE_ARRAY);
71
72
        return $result;
73 1
    }
74 1
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 1
     * 支払方法を取得
77
     * 条件によってはDoctrineのキャッシュが返されるため、arrayで結果を返すパターンも用意
78 1
     *
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
    public function findPayments($delivery, $returnType = false)
84
    {
85
86
        $query = $this->createQueryBuilder('p')
87
            ->innerJoin('Eccube\Entity\PaymentOption', 'po', 'WITH', 'po.payment_id = p.id')
88
            ->where('po.Delivery = (:delivery)')
89
            ->orderBy('p.rank', 'DESC')
90 25
            ->setParameter('delivery', $delivery)
91
            ->getQuery();
92
93 25
        $query->expireResultCache(false);
94 25
95 25
        if ($returnType) {
96 25
            $payments = $query->getResult();
97 25
        } else {
98 25
            $payments = $query->getArrayResult();
99
        }
100 25
101
        return $payments;
102 25
    }
103 11
104
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$deliveries" missing
Loading history...
introduced by
Doc comment for parameter "$retuenType" missing
Loading history...
105 24
     * 共通の支払方法を取得
106
     *
107
     * @param $deliveries
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
108 25
     * @return array
109
     */
110
    public function findAllowedPayments($deliveries, $retuenType = false)
111
    {
112
        $payments = array();
113
        $i = 0;
114
115
        foreach ($deliveries as $Delivery) {
116
            $p = $this->findPayments($Delivery, $retuenType);
117 24
118
            if ($i != 0) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
119 24
120 24
                $arr = array();
121
                foreach ($p as $payment) {
122 24
                    foreach ($payments as $pay) {
123 23
                        if ($payment['id'] == $pay['id']) {
124
                            $arr[] = $payment;
125 23
                            break;
126
                        }
127 3
                    }
128 3
                }
129 3
130 3
                $payments = $arr;
131 1
            } else {
132 3
                $payments = $p;
133
            }
134
            $i++;
135
        }
136
137 3
        return $payments;
138
    }
139
}
140