Conditions | 22 |
Paths | 22 |
Total Lines | 60 |
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 |
||
30 | public function toSQL() { |
||
31 | |||
32 | // Check the decorator. |
||
33 | if (null !== $this->decorator) { |
||
34 | return $this->decorator->toSQL($this); |
||
35 | } |
||
36 | |||
37 | // Initialize the SQL. |
||
38 | $sql = []; |
||
39 | $sql[] = $this->getField(); |
||
40 | $sql[] = self::OPERATORS[$this->operator]; |
||
41 | |||
42 | // Switch into operator. |
||
43 | switch ($this->operator) { |
||
44 | |||
45 | case self::OPERATOR_BEGINS_WITH: |
||
46 | case self::OPERATOR_NOT_BEGINS_WITH: |
||
47 | $sql[] = "'" . $this->quoteMixed($this->value, false) . "%'"; |
||
48 | break; |
||
49 | |||
50 | case self::OPERATOR_BETWEEN: |
||
51 | case self::OPERATOR_NOT_BETWEEN: |
||
52 | $sql[] = implode(" " . self::CONDITION_AND . " ", $this->quoteArray($this->value, true)); |
||
53 | break; |
||
54 | |||
55 | case self::OPERATOR_CONTAINS: |
||
56 | case self::OPERATOR_NOT_CONTAINS: |
||
57 | $sql[] = "'%" . $this->quoteMixed($this->value, false) . "%'"; |
||
58 | break; |
||
59 | |||
60 | case self::OPERATOR_ENDS_WITH: |
||
61 | case self::OPERATOR_NOT_ENDS_WITH: |
||
62 | $sql[] = "'%" . $this->quoteMixed($this->value, false) . "'"; |
||
63 | break; |
||
64 | |||
65 | case self::OPERATOR_EQUAL: |
||
66 | case self::OPERATOR_GREATER: |
||
67 | case self::OPERATOR_GREATER_OR_EQUAL: |
||
68 | case self::OPERATOR_LESS: |
||
69 | case self::OPERATOR_LESS_OR_EQUAL: |
||
70 | case self::OPERATOR_NOT_EQUAL: |
||
71 | $sql[] = $this->quoteMixed($this->value, true); |
||
72 | break; |
||
73 | |||
74 | case self::OPERATOR_IN: |
||
75 | case self::OPERATOR_NOT_IN: |
||
76 | $sql[] = "(" . implode(", ", $this->quoteArray($this->value, true)) . ")"; |
||
77 | break; |
||
78 | |||
79 | case self::OPERATOR_IS_EMPTY: |
||
80 | case self::OPERATOR_IS_NOT_EMPTY: |
||
81 | case self::OPERATOR_IS_NOT_NULL: |
||
82 | case self::OPERATOR_IS_NULL: |
||
83 | // NOTHING TO DO. |
||
84 | break; |
||
85 | } |
||
86 | |||
87 | // Return the SQL. |
||
88 | return implode(" ", $sql); |
||
89 | } |
||
90 | } |
||
91 |