Conditions | 10 |
Paths | 7 |
Total Lines | 31 |
Code Lines | 15 |
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 |
||
26 | public function buildLimitFragment(SQLSelect $query, array &$parameters) |
||
27 | { |
||
28 | $nl = $this->getSeparator(); |
||
29 | |||
30 | // Ensure limit is given |
||
31 | $limit = $query->getLimit(); |
||
32 | if (empty($limit)) { |
||
33 | return ''; |
||
34 | } |
||
35 | |||
36 | // For literal values return this as the limit SQL |
||
37 | if (! is_array($limit)) { |
||
|
|||
38 | return "{$nl}LIMIT $limit"; |
||
39 | } |
||
40 | |||
41 | // Assert that the array version provides the 'limit' key |
||
42 | if (! array_key_exists('limit', $limit) || ($limit['limit'] !== null && ! is_numeric($limit['limit']))) { |
||
43 | throw new InvalidArgumentException( |
||
44 | 'DBQueryBuilder::buildLimitSQL(): Wrong format for $limit: '. var_export($limit, true) |
||
45 | ); |
||
46 | } |
||
47 | |||
48 | if ($limit['limit'] === null) { |
||
49 | $limit['limit'] = 'ALL'; |
||
50 | } |
||
51 | |||
52 | $clause = "{$nl}LIMIT {$limit['limit']}"; |
||
53 | if (isset($limit['start']) && is_numeric($limit['start']) && $limit['start'] !== 0) { |
||
54 | $clause .= " OFFSET {$limit['start']}"; |
||
55 | } |
||
56 | return $clause; |
||
57 | } |
||
108 |