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 |
||
114 | public function buildQuery(array $params) |
||
115 | { |
||
116 | $jqb = new JoinQueryBuilder(); |
||
117 | $wqb = new WhereQueryBuilder(); |
||
118 | |||
119 | $prefix = $this->getPrefix(); |
||
120 | $tblWithPrefix = $params['table']; |
||
121 | $tbl = str_replace($prefix, '', $tblWithPrefix); |
||
122 | $query = []; |
||
123 | |||
124 | $query[] = 'SELECT'; |
||
125 | $query[] = $this->getQueryFields($params['fields'], $tbl); |
||
126 | $query[] = 'FROM'; |
||
127 | $query[] = $this->quote($tblWithPrefix).' AS '.$this->quote($tbl); |
||
128 | |||
129 | $query = $jqb->buildAllJoinQuery( |
||
130 | $params['join'], |
||
131 | $params['leftJoin'], |
||
132 | $params['rightJoin'], |
||
133 | $params['crossJoin'], |
||
134 | $query |
||
135 | ); |
||
136 | |||
137 | $query = $wqb->buildAllWhereQuery( |
||
138 | $params['where'], |
||
139 | $params['whereRaw'], |
||
140 | $params['whereIn'], |
||
141 | $params['whereNotIn'], |
||
142 | $params['whereNull'], |
||
143 | $params['whereNotNull'], |
||
144 | $query |
||
145 | ); |
||
146 | |||
147 | if (!empty($params['groupBy'])) { |
||
148 | $query[] = 'GROUP BY'; |
||
149 | $query[] = $params['groupBy']; |
||
150 | } |
||
151 | |||
152 | if (!empty($params['having'])) { |
||
153 | $query[] = 'HAVING'; |
||
154 | $query[] = $params['having']; |
||
155 | } |
||
156 | |||
157 | if (!empty($params['orderBy'])) { |
||
158 | $query[] = 'ORDER BY'; |
||
159 | $query[] = $params['orderBy']; |
||
160 | } |
||
161 | |||
162 | $query = $this->buildLimitQuery($params['limit'], $params['offset'], $query); |
||
163 | |||
164 | return $query; |
||
165 | } |
||
167 |