Conditions | 4 |
Paths | 8 |
Total Lines | 51 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
115 | public function buildQuery(array $params) |
||
116 | { |
||
117 | $jqb = new JoinQueryBuilder(); |
||
118 | $wqb = new WhereQueryBuilder(); |
||
119 | |||
120 | $prefix = $this->getPrefix(); |
||
121 | $tblWithPrefix = $params['table']; |
||
122 | $tbl = str_replace($prefix, '', $tblWithPrefix); |
||
123 | $query = []; |
||
124 | |||
125 | $query[] = 'SELECT'; |
||
126 | $query[] = $this->getQueryFields($params['fields'], $tbl); |
||
127 | $query[] = 'FROM'; |
||
128 | $query[] = $this->quote($tblWithPrefix).' AS '.$this->quote($tbl); |
||
129 | |||
130 | $query = $jqb->buildAllJoinQuery( |
||
131 | $params['join'], |
||
132 | $params['leftJoin'], |
||
133 | $params['rightJoin'], |
||
134 | $params['crossJoin'], |
||
135 | $query |
||
136 | ); |
||
137 | |||
138 | $query = $wqb->buildAllWhereQuery( |
||
139 | $params['where'], |
||
140 | $params['whereRaw'], |
||
141 | $params['whereIn'], |
||
142 | $params['whereNotIn'], |
||
143 | $params['whereNull'], |
||
144 | $params['whereNotNull'], |
||
145 | $query |
||
146 | ); |
||
147 | |||
148 | if (!empty($params['groupBy'])) { |
||
149 | $query[] = 'GROUP BY'; |
||
150 | $query[] = $params['groupBy']; |
||
151 | } |
||
152 | |||
153 | if (!empty($params['having'])) { |
||
154 | $query[] = 'HAVING'; |
||
155 | $query[] = $params['having']; |
||
156 | } |
||
157 | |||
158 | if (!empty($params['orderBy'])) { |
||
159 | $query[] = 'ORDER BY'; |
||
160 | $query[] = $params['orderBy']; |
||
161 | } |
||
162 | |||
163 | $query = $this->buildLimitQuery($params['limit'], $params['offset'], $query); |
||
164 | |||
165 | return $query; |
||
166 | } |
||
180 |