Failed Conditions
Pull Request — experimental/3.1 (#2285)
by Kiyotaka
41:31
created

JoinClause::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 6
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2017 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
namespace Eccube\Doctrine\Query;
25
26
27
use Doctrine\ORM\QueryBuilder;
28
29
/**
30
 * JOIN句を組み立てるクラス
31
 */
32
class JoinClause
33
{
34
35
    private $join;
36
37
    private $alias;
38
39
    private $conditionType;
40
41
    private $condition;
42
43
    private $indexBy;
44
45
    private $leftJoin = false;
46
47
    /**
48
     * @var JoinClauseWhereCustomizer $whereCustomizer
49
     */
50
    private $whereCustomizer;
51
52
    /**
53
     * @var JoinClauseOrderByCustomizer $orderByCustomizer
54
     */
55
    private $orderByCustomizer;
56
57
    /**
58
     * JoinClause constructor.
59
     * @param $leftJoin
60
     * @param $join
61
     * @param $alias
62
     * @param $conditionType
63
     * @param $condition
64
     * @param $indexBy
65
     */
66
    private function __construct($leftJoin, $join, $alias, $conditionType = null, $condition = null, $indexBy = null)
67
    {
68
        $this->leftJoin = $leftJoin;
69
        $this->join = $join;
70
        $this->alias = $alias;
71
        $this->conditionType = $conditionType;
72
        $this->condition = $condition;
73
        $this->indexBy = $indexBy;
74
        $this->whereCustomizer = new JoinClauseWhereCustomizer();
75
        $this->orderByCustomizer = new JoinClauseOrderByCustomizer();
76
    }
77
78
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$join" missing
Loading history...
introduced by
Doc comment for parameter "$alias" missing
Loading history...
introduced by
Doc comment for parameter "$conditionType" missing
Loading history...
introduced by
Doc comment for parameter "$condition" missing
Loading history...
introduced by
Doc comment for parameter "$indexBy" missing
Loading history...
79
     * INNER JOIN用のファクトリメソッド。
80
     *
81
     * @see QueryBuilder::innerJoin()
82
     * @param $join
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
83
     * @param $alias
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
84
     * @param $conditionType
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
85
     * @param $condition
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
86
     * @param $indexBy
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
87
     * @return JoinClause
88
     */
89
    public static function innerJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null)
90
    {
91
        return new JoinClause(false, $join, $alias, $conditionType, $condition, $indexBy);
92
    }
93
94
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$join" missing
Loading history...
introduced by
Doc comment for parameter "$alias" missing
Loading history...
introduced by
Doc comment for parameter "$conditionType" missing
Loading history...
introduced by
Doc comment for parameter "$condition" missing
Loading history...
introduced by
Doc comment for parameter "$indexBy" missing
Loading history...
95
     * LEFT JOIN用のファクトリメソッド。
96
     *
97
     * @see QueryBuilder::leftJoin()
98
     * @param $join
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
99
     * @param $alias
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
100
     * @param $conditionType
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
101
     * @param $condition
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
102
     * @param $indexBy
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
103
     * @return JoinClause
104
     */
105
    public static function leftJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null)
106
    {
107
        return new JoinClause(true, $join, $alias, $conditionType, $condition, $indexBy);
108
    }
109
110
    /**
111
     * WHERE句を追加します。
112
     *
113
     * @param WhereClause $whereClause
114
     * @return $this
115
     */
116
    public function addWhere(WhereClause $whereClause)
117
    {
118
        $this->whereCustomizer->add($whereClause);
119
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
120
    }
121
122
    /**
123
     * ORDER BY句を追加します。
124
     * @param OrderByClause $orderByClause
125
     * @return $this
126
     */
127
    public function addOrderBy(OrderByClause $orderByClause)
128
    {
129
        $this->orderByCustomizer->add($orderByClause);
130
        return $this;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
131
    }
132
133
    public function build(QueryBuilder $builder) {
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
134
        if ($this->leftJoin) {
135
            $builder->leftJoin($this->join, $this->alias, $this->conditionType, $this->condition, $this->indexBy);
136
        } else {
137
            $builder->innerJoin($this->join, $this->alias, $this->conditionType, $this->condition, $this->indexBy);
138
        }
139
        $this->whereCustomizer->customize($builder, null, '');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
140
        $this->orderByCustomizer->customize($builder, null, '');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
141
    }
142
}
143
144
class JoinClauseWhereCustomizer extends WhereCustomizer
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
introduced by
Missing class doc comment
Loading history...
introduced by
Multiple classes defined in a single file
Loading history...
145
{
146
    /**
147
     * @var WhereClause[]
148
     */
149
    private $whereClauses = [];
150
151
    public function add(WhereClause $whereClause)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
152
    {
153
        $this->whereClauses[] = $whereClause;
154
    }
155
156
    /**
157
     * @param array $params
158
     * @param $queryKey
159
     * @return WhereClause[]
160
     */
161
    protected function createStatements($params, $queryKey)
162
    {
163
        return $this->whereClauses;
164
    }
165
}
166
167
class JoinClauseOrderByCustomizer extends OrderByCustomizer
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
introduced by
Missing class doc comment
Loading history...
introduced by
Multiple classes defined in a single file
Loading history...
168
{
169
    /**
170
     * @var OrderByClause[]
171
     */
172
    private $orderByClauses = [];
173
174
    public function add(OrderByClause $orderByClause)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
175
    {
176
        $this->orderByClauses[] = $orderByClause;
177
    }
178
179
    /**
180
     * @param array $params
181
     * @param $queryKey
182
     * @return OrderByClause[]
183
     */
184
    protected function createStatements($params, $queryKey)
185
    {
186
        return $this->orderByClauses;
187
    }
188
}