| Conditions | 14 |
| Paths | 72 |
| Total Lines | 54 |
| 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 |
||
| 226 | private function build() { |
||
| 227 | $params = array(); |
||
| 228 | $sqlSelect = implode(', ', $this->_select); |
||
| 229 | $sql = "SELECT SQL_CALC_FOUND_ROWS $sqlSelect \nFROM `{$this->_tableName}` "; |
||
| 230 | if (!empty($this->_alias)) { |
||
| 231 | $sql .= ' '.$this->_alias; |
||
| 232 | } |
||
| 233 | if (!empty($this->_join)) { |
||
| 234 | $sql .= "\n"; |
||
| 235 | /** @var $chunk JoinChunk */ |
||
| 236 | foreach ($this->_join as $chunk) { |
||
| 237 | $sql .= $chunk->build(); |
||
| 238 | } |
||
| 239 | } |
||
| 240 | if (!empty($this->_where)) { |
||
| 241 | $arr = array(); |
||
| 242 | /** @var $chunk WhereChunk */ |
||
| 243 | foreach ($this->_where as $chunk) { |
||
| 244 | list($wSQL, $wParams) = $chunk->build(); |
||
| 245 | $arr[] = $wSQL; |
||
| 246 | foreach ($wParams as $k=>$v) { |
||
| 247 | $params[$k] = $v; |
||
| 248 | } |
||
| 249 | } |
||
| 250 | $sql .= " WHERE ".implode(' AND ', $arr); |
||
| 251 | } |
||
| 252 | if (!empty($this->_sort)) { |
||
| 253 | $arr = array(); |
||
| 254 | foreach ($this->_sort as $k=>$v) { |
||
| 255 | if ($k) { |
||
| 256 | if ($v) { |
||
| 257 | $arr[] = "{$k} {$v}"; |
||
| 258 | } else { |
||
| 259 | $arr[] = "$k"; |
||
| 260 | } |
||
| 261 | } |
||
| 262 | } |
||
| 263 | if (!empty($arr)) { |
||
| 264 | $sql .= " ORDER BY "; |
||
| 265 | $sql .= implode(', ', $arr); |
||
| 266 | } |
||
| 267 | } |
||
| 268 | if ($this->_pageSize) { |
||
| 269 | if ($this->_pageNum) { |
||
| 270 | $from = ($this->_pageNum - 1) * $this->_pageSize; |
||
| 271 | $sql .= " LIMIT {$from}, {$this->_pageSize} "; |
||
| 272 | } else { |
||
| 273 | $sql .= " LIMIT {$this->_pageSize} "; |
||
| 274 | } |
||
| 275 | } |
||
| 276 | $params = array_merge($params, $this->_params); |
||
| 277 | //print $sql; |
||
| 278 | return array($sql, $params); |
||
| 279 | } |
||
| 280 | |||
| 282 |
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.