| Conditions | 10 |
| Paths | 10 |
| Total Lines | 48 |
| 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 |
||
| 76 | public function handle(SelectQuery $query, Criterion $criterion, $column) |
||
| 77 | { |
||
| 78 | $column = $this->dbHandler->quoteColumn($column); |
||
| 79 | |||
| 80 | switch ($criterion->operator) { |
||
| 81 | case Criterion\Operator::IN: |
||
| 82 | $filter = $query->expr->in( |
||
| 83 | $column, |
||
| 84 | array_map(array($this, 'lowercase'), $criterion->value) |
||
| 85 | ); |
||
| 86 | break; |
||
| 87 | |||
| 88 | case Criterion\Operator::BETWEEN: |
||
| 89 | $filter = $query->expr->between( |
||
| 90 | $column, |
||
| 91 | $query->bindValue($this->lowercase($criterion->value[0])), |
||
| 92 | $query->bindValue($this->lowercase($criterion->value[1])) |
||
| 93 | ); |
||
| 94 | break; |
||
| 95 | |||
| 96 | case Criterion\Operator::EQ: |
||
| 97 | case Criterion\Operator::GT: |
||
| 98 | case Criterion\Operator::GTE: |
||
| 99 | case Criterion\Operator::LT: |
||
| 100 | case Criterion\Operator::LTE: |
||
| 101 | case Criterion\Operator::LIKE: |
||
| 102 | $operatorFunction = $this->comparatorMap[$criterion->operator]; |
||
| 103 | $filter = $query->expr->$operatorFunction( |
||
| 104 | $column, |
||
| 105 | $query->bindValue($this->lowercase($criterion->value)) |
||
| 106 | ); |
||
| 107 | break; |
||
| 108 | |||
| 109 | case Criterion\Operator::CONTAINS: |
||
| 110 | $filter = $query->expr->like( |
||
| 111 | $column, |
||
| 112 | $query->bindValue( |
||
| 113 | '%' . $this->prepareLikeString($criterion->value) . '%' |
||
| 114 | ) |
||
| 115 | ); |
||
| 116 | break; |
||
| 117 | |||
| 118 | default: |
||
| 119 | throw new RuntimeException("Unknown operator '{$criterion->operator}' for Field criterion handler."); |
||
| 120 | } |
||
| 121 | |||
| 122 | return $filter; |
||
| 123 | } |
||
| 124 | |||
| 151 |