| Conditions | 10 |
| Paths | 7 |
| Total Lines | 34 |
| Code Lines | 18 |
| 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 buildLimitFragment(SQLSelect $query, array &$parameters) |
||
| 74 | { |
||
| 75 | $nl = $this->getSeparator(); |
||
| 76 | |||
| 77 | // Ensure limit is given |
||
| 78 | $limit = $query->getLimit(); |
||
| 79 | if (empty($limit)) { |
||
| 80 | return ''; |
||
| 81 | } |
||
| 82 | |||
| 83 | // For literal values return this as the limit SQL |
||
| 84 | if (! is_array($limit)) { |
||
| 85 | return "{$nl}LIMIT $limit"; |
||
| 86 | } |
||
| 87 | |||
| 88 | // Assert that the array version provides the 'limit' key |
||
| 89 | if (! array_key_exists('limit', $limit) || ($limit['limit'] !== null && ! is_numeric($limit['limit']))) { |
||
| 90 | throw new InvalidArgumentException( |
||
| 91 | 'SQLite3QueryBuilder::buildLimitSQL(): Wrong format for $limit: '. var_export($limit, true) |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | |||
| 95 | $clause = "{$nl}"; |
||
| 96 | if ($limit['limit'] !== null) { |
||
| 97 | $clause .= "LIMIT {$limit['limit']} "; |
||
| 98 | } else { |
||
| 99 | $clause .= "LIMIT -1 "; |
||
| 100 | } |
||
| 101 | |||
| 102 | if (isset($limit['start']) && is_numeric($limit['start']) && $limit['start'] !== 0) { |
||
| 103 | $clause .= "OFFSET {$limit['start']}"; |
||
| 104 | } |
||
| 105 | return $clause; |
||
| 106 | } |
||
| 107 | } |
||
| 108 |