Conditions | 4 |
Paths | 4 |
Total Lines | 56 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
28 | protected function compileLegacyGroupLimit(Builder $query) |
||
29 | { |
||
30 | $limit = (int)$query->groupLimit['value'] + (int)$query->offset; |
||
|
|||
31 | $offset = $query->offset; |
||
32 | |||
33 | $query->offset = null; |
||
34 | $query->orders = (array)$query->orders; |
||
35 | |||
36 | $partitionExpressions = []; |
||
37 | $partitionAssignments = []; |
||
38 | $partitionInitializations = []; |
||
39 | $partitionOrders = []; |
||
40 | |||
41 | if (is_array($query->groupLimit['column'])) { |
||
42 | foreach ($query->groupLimit['column'] as $i => $column) { |
||
43 | $wrappedColumn = $this->wrap(last(explode('.', $column))); |
||
44 | |||
45 | $partitionExpressions[] = "@laravel_partition_$i = $wrappedColumn"; |
||
46 | $partitionAssignments[] = "@laravel_partition_$i := $wrappedColumn"; |
||
47 | $partitionInitializations[] = "@laravel_partition_$i := 0"; |
||
48 | $partitionOrders[] = ['column' => $column, 'direction' => 'asc']; |
||
49 | } |
||
50 | } else { |
||
51 | $wrappedColumn = $this->wrap(last(explode('.', $query->groupLimit['column']))); |
||
52 | |||
53 | $partitionExpressions[] = "@laravel_partition = $wrappedColumn"; |
||
54 | $partitionAssignments[] = "@laravel_partition := $wrappedColumn"; |
||
55 | $partitionInitializations[] = '@laravel_partition := 0'; |
||
56 | $partitionOrders[] = ['column' => $query->groupLimit['column'], 'direction' => 'asc']; |
||
57 | } |
||
58 | |||
59 | $partition = sprintf( |
||
60 | ', @laravel_row := if(%s, @laravel_row + 1, 1) as laravel_row, %s', |
||
61 | implode(' and ', $partitionExpressions), |
||
62 | implode(', ', $partitionAssignments) |
||
63 | ); |
||
64 | |||
65 | array_splice($query->orders, 0, 0, $partitionOrders); |
||
66 | |||
67 | $components = $this->compileComponents($query); |
||
68 | |||
69 | $sql = $this->concatenate($components); |
||
70 | |||
71 | $from = sprintf( |
||
72 | '(select @laravel_row := 0, %s) as laravel_vars, (%s) as laravel_table', |
||
73 | implode(', ', $partitionInitializations), |
||
74 | $sql |
||
75 | ); |
||
76 | |||
77 | $sql = 'select laravel_table.*' . $partition . ' from ' . $from . ' having laravel_row <= ' . $limit; |
||
78 | |||
79 | if ($offset !== null) { |
||
80 | $sql .= ' and laravel_row > ' . (int)$offset; |
||
81 | } |
||
82 | |||
83 | return $sql . ' order by laravel_row'; |
||
84 | } |
||
86 |