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 |
||
98 | public function buildQuery(array $params) |
||
99 | { |
||
100 | $jqb = new JoinQueryBuilder(); |
||
101 | $wqb = new WhereQueryBuilder(); |
||
102 | |||
103 | $prefix = $this->getPrefix(); |
||
104 | $tblWithPrefix = $params['table']; |
||
105 | $tbl = str_replace($prefix, '', $tblWithPrefix); |
||
106 | $query = []; |
||
107 | |||
108 | $query[] = 'SELECT'; |
||
109 | $query[] = $this->getQueryFields($params['fields'], $tbl); |
||
110 | $query[] = 'FROM'; |
||
111 | $query[] = $this->quote($tblWithPrefix).' AS '.$this->quote($tbl); |
||
112 | |||
113 | $query = $jqb->buildAllJoinQuery( |
||
114 | $params['join'], |
||
115 | $params['leftJoin'], |
||
116 | $params['rightJoin'], |
||
117 | $params['crossJoin'], |
||
118 | $query |
||
119 | ); |
||
120 | |||
121 | $query = $wqb->buildAllWhereQuery( |
||
122 | $params['where'], |
||
123 | $params['whereRaw'], |
||
124 | $params['whereIn'], |
||
125 | $params['whereNotIn'], |
||
126 | $params['whereNull'], |
||
127 | $params['whereNotNull'], |
||
128 | $query |
||
129 | ); |
||
130 | |||
131 | if (!empty($params['groupBy'])) { |
||
132 | $query[] = 'GROUP BY'; |
||
133 | $query[] = $params['groupBy']; |
||
134 | } |
||
135 | |||
136 | if (!empty($params['having'])) { |
||
137 | $query[] = 'HAVING'; |
||
138 | $query[] = $params['having']; |
||
139 | } |
||
140 | |||
141 | if (!empty($params['orderBy'])) { |
||
142 | $query[] = 'ORDER BY'; |
||
143 | $query[] = $params['orderBy']; |
||
144 | } |
||
145 | |||
146 | $query = $this->buildLimitQuery($params['limit'], $params['offset'], $query); |
||
147 | |||
148 | return $query; |
||
149 | } |
||
151 |