| Conditions | 9 |
| Paths | 256 |
| Total Lines | 51 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 38 |
| CRAP Score | 9 |
| Changes | 5 | ||
| Bugs | 0 | Features | 3 |
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 |
||
| 24 | 21 | public function compile(QueryBuilder $qb) |
|
| 25 | { |
||
| 26 | 21 | $commaSeparated = new SeparatedListCompiler(', '); |
|
| 27 | 21 | $andSeparated = new SeparatedListCompiler(' AND '); |
|
| 28 | 21 | $spaceSeparated = new SeparatedListCompiler(' '); |
|
| 29 | |||
| 30 | 21 | $select = $commaSeparated->compile($qb->getSelectClauses()); |
|
| 31 | 21 | $afterSelectHints = $spaceSeparated->compile($qb->getHints()); |
|
| 32 | 21 | $where = $andSeparated->compile($qb->getWhereClauses()); |
|
| 33 | 21 | $from = $commaSeparated->compile($qb->getRootTables()); |
|
| 34 | 21 | $join = $spaceSeparated->compile($qb->getJoinTables()); |
|
| 35 | 21 | $orderBy = $commaSeparated->compile($qb->getOrderByClauses()); |
|
| 36 | 21 | $groupBy = $commaSeparated->compile($qb->getGroupByClauses()); |
|
| 37 | 21 | $having = $andSeparated->compile($qb->getHavingClauses()); |
|
| 38 | |||
| 39 | 21 | $sql = "SELECT"; |
|
| 40 | |||
| 41 | 21 | if ($afterSelectHints) { |
|
| 42 | 1 | $sql .= ' ' . $afterSelectHints; |
|
| 43 | 1 | } |
|
| 44 | |||
| 45 | 21 | if ($select) { |
|
| 46 | 21 | $sql .= ' ' . $select; |
|
| 47 | 21 | } |
|
| 48 | |||
| 49 | 21 | if ($from) { |
|
| 50 | 20 | $sql .= ' FROM ' . $from; |
|
| 51 | 20 | } |
|
| 52 | |||
| 53 | 21 | if ($join) { |
|
| 54 | 3 | $sql .= ' ' . $join; |
|
| 55 | 3 | } |
|
| 56 | |||
| 57 | 21 | if ($where) { |
|
| 58 | 3 | $sql .= ' WHERE ' . $where; |
|
| 59 | 3 | } |
|
| 60 | |||
| 61 | 21 | if ($groupBy) { |
|
| 62 | 2 | $sql .= ' GROUP BY ' . $groupBy; |
|
| 63 | 2 | } |
|
| 64 | |||
| 65 | 21 | if ($having) { |
|
| 66 | 1 | $sql .= ' HAVING ' . $having; |
|
| 67 | 1 | } |
|
| 68 | |||
| 69 | 21 | if ($orderBy) { |
|
| 70 | 1 | $sql .= ' ORDER BY ' . $orderBy; |
|
| 71 | 1 | } |
|
| 72 | |||
| 73 | 21 | return $sql; |
|
| 74 | } |
||
| 75 | } |