Failed Conditions
Pull Request — master (#1665)
by k-yamamura
74:32
created

DeliveryRepository   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 91.89%

Importance

Changes 0
Metric Value
dl 0
loc 86
ccs 34
cts 37
cp 0.9189
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
B findOrCreate() 0 32 3
A getDeliveries() 0 12 1
B findAllowedDeliveries() 0 25 6
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\Entity\Payment;
29
30
/**
31
 * DelivRepository
32
 *
33
 * This class was generated by the Doctrine ORM. Add your own custom
34
 * repository methods below.
35
 */
36
class DeliveryRepository extends EntityRepository
37
{
38 8
    public function findOrCreate($id)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
39
    {
40 8
        if ($id == 0) {
41 8
            $em = $this->getEntityManager();
42
            $Creator = $em
43 8
                ->getRepository('\Eccube\Entity\Member')
44 8
                ->find(2);
45
            $ProductType = $em
46 8
                ->getRepository('\Eccube\Entity\Master\ProductType')
47 8
                ->find(1);
48
49 8
            $Delivery = $this->findOneBy(array(), array('rank' => 'DESC'));
50
51 8
            $rank = 1;
52 8
            if ($Delivery) {
53 8
                $rank = $Delivery->getRank() + 1;
54
            }
55
56 8
            $Delivery = new \Eccube\Entity\Delivery();
57
            $Delivery
58 8
                ->setRank($rank)
59 8
                ->setDelFlg(0)
60 8
                ->setCreator($Creator)
61 8
                ->setProductType($ProductType);
62
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
63
        } else {
64 3
            $Delivery = $this->find($id);
65
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
66
        }
67
68 8
        return $Delivery;
69
    }
70
71
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$productTypes" missing
Loading history...
72
     * 複数の商品種別から配送業者を取得
73
     *
74
     * @param $productTypes
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
75
     * @return array
76
     */
77 131
    public function getDeliveries($productTypes)
78
    {
79
80 131
        $deliveries = $this->createQueryBuilder('d')
81 131
            ->where('d.ProductType in (:productTypes)')
82 131
            ->setParameter('productTypes', $productTypes)
83 131
            ->getQuery()
84 131
            ->getResult();
85
86 131
        return $deliveries;
87
88
    }
89
90
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$payments" missing
Loading history...
introduced by
Doc comment for parameter "$productTypes" missing
Loading history...
91
     * 選択可能な配送業者を取得
92
     *
93
     * @param $payments
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
94
     * @return array
95
     */
96 2
    public function findAllowedDeliveries($productTypes, $payments)
97
    {
98
99 2
        $d = $this->getDeliveries($productTypes);
100 2
        $arr = array();
101
102 2
        foreach ($d as $Delivery) {
103 1
            $paymentOptions = $Delivery->getPaymentOptions();
104
105 1
            foreach ($paymentOptions as $PaymentOption) {
106 1
                foreach ($payments as $Payment) {
107
                    if ($PaymentOption->getPayment() instanceof Payment) {
0 ignored issues
show
Bug introduced by
The class Eccube\Entity\Payment 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...
108
                        if ($PaymentOption->getPayment()->getId() == $Payment['id']) {
109
                            $arr[$Delivery->getId()] = $Delivery;
110 2
                            break;
111
                        }
112
                    }
113
                }
114
            }
115
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
116
        }
117
118 2
        return array_values($arr);
119
120
    }
121
}
122