| Conditions | 8 |
| Paths | 96 |
| Total Lines | 63 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | 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 |
||
| 80 | public function buildQuery(array $params) |
||
| 81 | { |
||
| 82 | $jqb = new JoinQueryBuilder(); |
||
| 83 | $wqb = new WhereQueryBuilder(); |
||
| 84 | |||
| 85 | $prefix = $this->getPrefix(); |
||
| 86 | $tblWithPrefix = $params['table']; |
||
| 87 | $tbl = str_replace($prefix, '', $tblWithPrefix); |
||
| 88 | $query = []; |
||
| 89 | |||
| 90 | $query[] = 'SELECT'; |
||
| 91 | $query[] = $this->getQueryFields($params['fields'], $tbl); |
||
| 92 | $query[] = 'FROM'; |
||
| 93 | $query[] = $this->quote($tblWithPrefix).' AS '.$this->quote($tbl); |
||
| 94 | |||
| 95 | $allJoinQuery = $jqb->buildAllJoinQuery( |
||
| 96 | $params['join'], |
||
| 97 | $params['leftJoin'], |
||
| 98 | $params['rightJoin'], |
||
| 99 | $params['crossJoin'] |
||
| 100 | ); |
||
| 101 | if (count($allJoinQuery)) { |
||
| 102 | $query = array_merge($query, $allJoinQuery); |
||
| 103 | } |
||
| 104 | |||
| 105 | $allWhereQuery = $wqb->buildAllWhereQuery( |
||
| 106 | $params['where'], |
||
| 107 | $params['whereRaw'], |
||
| 108 | $params['whereIn'], |
||
| 109 | $params['whereNotIn'], |
||
| 110 | $params['whereNull'], |
||
| 111 | $params['whereNotNull'] |
||
| 112 | ); |
||
| 113 | if (count($allWhereQuery)) { |
||
| 114 | $query = array_merge($query, $allWhereQuery); |
||
| 115 | } |
||
| 116 | |||
| 117 | if (!empty($params['groupBy'])) { |
||
| 118 | $query[] = 'GROUP BY'; |
||
| 119 | $query[] = $params['groupBy']; |
||
| 120 | } |
||
| 121 | |||
| 122 | if (!empty($params['having'])) { |
||
| 123 | $query[] = 'HAVING'; |
||
| 124 | $query[] = $params['having']; |
||
| 125 | } |
||
| 126 | |||
| 127 | if (!empty($params['orderBy'])) { |
||
| 128 | $query[] = 'ORDER BY'; |
||
| 129 | $query[] = $params['orderBy']; |
||
| 130 | } |
||
| 131 | |||
| 132 | if (!empty($params['limit'])) { |
||
| 133 | $query[] = 'LIMIT'; |
||
| 134 | |||
| 135 | if (!empty($params['offset'])) { |
||
| 136 | $query[] = $params['offset'].','; |
||
| 137 | } |
||
| 138 | |||
| 139 | $query[] = $params['limit']; |
||
| 140 | } |
||
| 141 | |||
| 142 | return $query; |
||
| 143 | } |
||
| 145 |