Conditions | 21 |
Paths | 21 |
Total Lines | 52 |
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 |
||
36 | public static function queryBuilderRule2SQL(QueryBuilderRuleInterface $rule) { |
||
37 | |||
38 | $sql = []; |
||
39 | $sql[] = $rule->getField(); |
||
40 | $sql[] = QueryBuilderEnumerator::enumOperators()[$rule->getOperator()]; |
||
41 | |||
42 | switch ($rule->getOperator()) { |
||
43 | |||
44 | case self::OPERATOR_BEGINS_WITH: |
||
45 | case self::OPERATOR_NOT_BEGINS_WITH: |
||
46 | $sql[] = "'" . static::quoteMixedValue($rule->getType(), $rule->getValue(), false) . "%'"; |
||
47 | break; |
||
48 | |||
49 | case self::OPERATOR_BETWEEN: |
||
50 | case self::OPERATOR_NOT_BETWEEN: |
||
51 | $sql[] = implode(" " . self::CONDITION_AND . " ", static::quoteArrayValue($rule->getType(), $rule->getValue(), true)); |
||
52 | break; |
||
53 | |||
54 | case self::OPERATOR_CONTAINS: |
||
55 | case self::OPERATOR_NOT_CONTAINS: |
||
56 | $sql[] = "'%" . static::quoteMixedValue($rule->getType(), $rule->getValue(), false) . "%'"; |
||
57 | break; |
||
58 | |||
59 | case self::OPERATOR_ENDS_WITH: |
||
60 | case self::OPERATOR_NOT_ENDS_WITH: |
||
61 | $sql[] = "'%" . static::quoteMixedValue($rule->getType(), $rule->getValue(), false) . "'"; |
||
62 | break; |
||
63 | |||
64 | case self::OPERATOR_EQUAL: |
||
65 | case self::OPERATOR_GREATER: |
||
66 | case self::OPERATOR_GREATER_OR_EQUAL: |
||
67 | case self::OPERATOR_LESS: |
||
68 | case self::OPERATOR_LESS_OR_EQUAL: |
||
69 | case self::OPERATOR_NOT_EQUAL: |
||
70 | $sql[] = static::quoteMixedValue($rule->getType(), $rule->getValue(), true); |
||
71 | break; |
||
72 | |||
73 | case self::OPERATOR_IN: |
||
74 | case self::OPERATOR_NOT_IN: |
||
75 | $sql[] = "(" . implode(", ", static::quoteArrayValue($rule->getType(), $rule->getValue(), true)) . ")"; |
||
76 | break; |
||
77 | |||
78 | case self::OPERATOR_IS_EMPTY: |
||
79 | case self::OPERATOR_IS_NOT_EMPTY: |
||
80 | case self::OPERATOR_IS_NOT_NULL: |
||
81 | case self::OPERATOR_IS_NULL: |
||
82 | // NOTHING TO DO. |
||
83 | break; |
||
84 | } |
||
85 | |||
86 | return implode(" ", $sql); |
||
87 | } |
||
88 | |||
169 |