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