| Conditions | 16 |
| Paths | 28 |
| Total Lines | 42 |
| Code Lines | 34 |
| 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 |
||
| 108 | protected function filter(Builder $query, string $key, string $column, $value, $type): Builder |
||
| 109 | { |
||
| 110 | $type = $type ?: 'AND'; |
||
| 111 | |||
| 112 | $likeOperator = $this->getCaseInsensitiveLikeOperator(); |
||
| 113 | |||
| 114 | $table = $query->getModel()->getTable(); |
||
| 115 | $qualifiedColumn = $table.'.'.$column; |
||
| 116 | |||
| 117 | $value = $value instanceof Arguments ? $value->toArray() : $value; |
||
| 118 | |||
| 119 | if (Str::endsWith($key, 'NotContains')) { |
||
| 120 | $query->where($qualifiedColumn, 'NOT '.$likeOperator, '%'.$value.'%', $type); |
||
|
|
|||
| 121 | } elseif (Str::endsWith($key, 'Contains')) { |
||
| 122 | $query->where($qualifiedColumn, $likeOperator, '%'.$value.'%', $type); |
||
| 123 | } elseif (Str::endsWith($key, 'NotStartsWith')) { |
||
| 124 | $query->where($qualifiedColumn, 'NOT '.$likeOperator, $value.'%', $type); |
||
| 125 | } elseif (Str::endsWith($key, 'StartsWith')) { |
||
| 126 | $query->where($qualifiedColumn, $likeOperator, $value.'%', $type); |
||
| 127 | } elseif (Str::endsWith($key, 'NotEndsWith')) { |
||
| 128 | $query->where($qualifiedColumn, 'NOT '.$likeOperator, '%'.$value, $type); |
||
| 129 | } elseif (Str::endsWith($key, 'EndsWith')) { |
||
| 130 | $query->where($qualifiedColumn, $likeOperator, '%'.$value, $type); |
||
| 131 | } elseif (Str::endsWith($key, 'Not')) { |
||
| 132 | $query->where($qualifiedColumn, '!=', $value, $type); |
||
| 133 | } elseif (Str::endsWith($key, 'NotIn')) { |
||
| 134 | $query->whereNotIn($qualifiedColumn, $value, $type); |
||
| 135 | } elseif (Str::endsWith($key, 'In')) { |
||
| 136 | $query->whereIn($qualifiedColumn, $value, $type); |
||
| 137 | } elseif (Str::endsWith($key, 'LessThan')) { |
||
| 138 | $query->where($qualifiedColumn, '<', $value, $type); |
||
| 139 | } elseif (Str::endsWith($key, 'LessThanOrEquals')) { |
||
| 140 | $query->where($qualifiedColumn, '<=', $value, $type); |
||
| 141 | } elseif (Str::endsWith($key, 'GreaterThan')) { |
||
| 142 | $query->where($qualifiedColumn, '>', $value, $type); |
||
| 143 | } elseif (Str::endsWith($key, 'GreaterThanOrEquals')) { |
||
| 144 | $query->where($qualifiedColumn, '>=', $value, $type); |
||
| 145 | } else { |
||
| 146 | $query->where($qualifiedColumn, '=', $value, $type); |
||
| 147 | } |
||
| 148 | |||
| 149 | return $query; |
||
| 150 | } |
||
| 183 |