Conditions | 24 |
Paths | 25 |
Total Lines | 45 |
Code Lines | 39 |
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 |
||
80 | protected function parseRuleToQuery($query, $rule, $condition = 'AND') |
||
81 | { |
||
82 | list($field, $op, $value) = $this->expandRule($rule); |
||
83 | |||
84 | switch ($op) { |
||
85 | case 'equal': |
||
86 | case 'not_equal': |
||
87 | case 'less': |
||
88 | case 'less_or_equal': |
||
89 | case 'greater': |
||
90 | case 'greater_or_equal': |
||
91 | case 'regex': |
||
92 | case 'not_regex': |
||
93 | return $query->where($field, self::$operators[$op], $value, $condition); |
||
94 | case 'contains': |
||
95 | case 'not_contains': |
||
96 | return $query->where($field, self::$operators[$op], "%$value%", $condition); |
||
97 | case 'begins_with': |
||
98 | case 'not_begins_with': |
||
99 | return $query->where($field, self::$operators[$op], "$value%", $condition); |
||
100 | case 'ends_with': |
||
101 | case 'not_ends_with': |
||
102 | return $query->where($field, self::$operators[$op], "%$value", $condition); |
||
103 | case 'is_empty': |
||
104 | case 'is_not_empty': |
||
105 | return $query->where($field, self::$operators[$op], ''); |
||
106 | case 'is_null': |
||
107 | case 'is_not_null': |
||
108 | return $query->whereNull($field, $condition, $op == 'is_not_null'); |
||
109 | case 'between': |
||
110 | case 'not_between': |
||
111 | return $query->whereBetween($field, $value, $condition, $op == 'not_between'); |
||
112 | case 'in': |
||
113 | case 'not_in': |
||
114 | $values = preg_split('/[, ]/', $value); |
||
115 | if ($values !== false) { |
||
116 | return $query->whereIn($field, $values, $condition, $op == 'not_in'); |
||
117 | } |
||
118 | Log::error('Could not parse in values, use comma or space delimiters'); |
||
119 | break; |
||
120 | default: |
||
121 | Log::error('Unhandled QueryBuilderFluentParser operation: ' . $op); |
||
122 | } |
||
123 | |||
124 | return $query; |
||
125 | } |
||
167 |