Conditions | 11 |
Paths | 11 |
Total Lines | 27 |
Code Lines | 24 |
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 |
||
88 | private function getExpression(ExpressionBuilderInterface $expressionBuilder, $type, $field, $value) |
||
89 | { |
||
90 | switch ($type) { |
||
91 | case self::TYPE_EQUAL: |
||
92 | return $expressionBuilder->equals($field, $value); |
||
93 | case self::TYPE_NOT_EQUAL: |
||
94 | return $expressionBuilder->notEquals($field, $value); |
||
95 | case self::TYPE_EMPTY: |
||
96 | return $expressionBuilder->isNull($field); |
||
97 | case self::TYPE_NOT_EMPTY: |
||
98 | return $expressionBuilder->isNotNull($field); |
||
99 | case self::TYPE_CONTAINS: |
||
100 | return $expressionBuilder->like($field, '%'.$value.'%'); |
||
101 | case self::TYPE_NOT_CONTAINS: |
||
102 | return $expressionBuilder->notLike($field, '%'.$value.'%'); |
||
103 | case self::TYPE_STARTS_WITH: |
||
104 | return $expressionBuilder->like($field, $value.'%'); |
||
105 | case self::TYPE_ENDS_WITH: |
||
106 | return $expressionBuilder->like($field, '%'.$value); |
||
107 | case self::TYPE_IN: |
||
108 | return $expressionBuilder->in($field, array_map('trim', explode(',', $value))); |
||
109 | case self::TYPE_NOT_IN: |
||
110 | return $expressionBuilder->notIn($field, array_map('trim', explode(',', $value))); |
||
111 | default: |
||
112 | throw new \InvalidArgumentException(sprintf('Could not get an expression for type "%s"!', $type)); |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 |