Conditions | 10 |
Paths | 10 |
Total Lines | 32 |
Code Lines | 29 |
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 |
||
71 | private function getExpression(ExpressionBuilderInterface $expressionBuilder, $type, $field, $value) |
||
72 | { |
||
73 | switch ($type) { |
||
74 | case self::TYPE_EQUAL: |
||
75 | return $expressionBuilder->equals($field, $value); |
||
76 | break; |
||
|
|||
77 | case self::TYPE_EMPTY: |
||
78 | return $expressionBuilder->isNull($field); |
||
79 | break; |
||
80 | case self::TYPE_NOT_EMPTY: |
||
81 | return $expressionBuilder->isNotNull($field); |
||
82 | break; |
||
83 | case self::TYPE_CONTAINS: |
||
84 | return $expressionBuilder->like($field, '%'.$value.'%'); |
||
85 | break; |
||
86 | case self::TYPE_NOT_CONTAINS: |
||
87 | return $expressionBuilder->notLike($field, '%'.$value.'%'); |
||
88 | break; |
||
89 | case self::TYPE_STARTS_WITH: |
||
90 | return $expressionBuilder->like($field, $value.'%'); |
||
91 | break; |
||
92 | case self::TYPE_ENDS_WITH: |
||
93 | return $expressionBuilder->like($field, '%'.$value); |
||
94 | break; |
||
95 | case self::TYPE_IN: |
||
96 | return $expressionBuilder->in($field, array_map('trim', explode(',', $value))); |
||
97 | break; |
||
98 | case self::TYPE_NOT_IN: |
||
99 | return $expressionBuilder->notIn($field, array_map('trim', explode(',', $value))); |
||
100 | break; |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.