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