| Conditions | 10 |
| Paths | 129 |
| Total Lines | 55 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 166 | public function select(array $infos) |
||
| 167 | { |
||
| 168 | try { |
||
| 169 | |||
| 170 | $tabela = $infos['table']; |
||
| 171 | $campos = $infos['fields']; |
||
| 172 | |||
| 173 | $whereCriteria = $infos['where']; |
||
| 174 | $joins = $infos['join']; |
||
| 175 | $limitCriteria = $infos['limit']; |
||
| 176 | $offsetCriteria = $infos['offset']; |
||
| 177 | $orderByCriteria = $infos['orderby']; |
||
| 178 | |||
| 179 | $campos = gettype($campos) == "array" ? implode(", ", $campos) : $campos; |
||
| 180 | |||
| 181 | $this->sql = "SELECT " . $campos . " FROM $tabela"; |
||
| 182 | |||
| 183 | // responsável por montar JOIN |
||
| 184 | if (!empty($joins)) { |
||
| 185 | for ($i = 0; $i < count($joins); $i++) { |
||
| 186 | $this->sql .= " " . $joins[$i] . " "; |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | // responsável por montar o WHERE. |
||
| 191 | if (!empty($whereCriteria)) { |
||
| 192 | $this->sql .= " WHERE " . $whereCriteria; |
||
| 193 | } |
||
| 194 | |||
| 195 | // responsável por montar o order by. |
||
| 196 | if (!is_null($orderByCriteria)) { |
||
| 197 | $orderBy = gettype($orderByCriteria) == "array" ? implode(", ", $orderByCriteria) : $orderByCriteria; |
||
| 198 | |||
| 199 | $this->sql .= " ORDER BY " . $orderBy; |
||
| 200 | } |
||
| 201 | |||
| 202 | // responsável por montar o limit. |
||
| 203 | if (!empty($limitCriteria)) { |
||
| 204 | $this->sql .= " LIMIT " . $limitCriteria; |
||
| 205 | } |
||
| 206 | |||
| 207 | // responsável por montar OFFSET |
||
| 208 | if (!empty($offsetCriteria)) { |
||
| 209 | |||
| 210 | $this->sql .= " OFFSET " . $offsetCriteria; |
||
| 211 | } |
||
| 212 | |||
| 213 | $this->sql .= ";"; |
||
| 214 | |||
| 215 | return $this->sql; |
||
| 216 | |||
| 217 | } catch (PhiberException $phiberException) { |
||
| 218 | throw new PhiberException(new Internationalization("query_processor_error")); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | } |
||
| 222 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.