| Conditions | 21 |
| Paths | 139 |
| Total Lines | 56 |
| Code Lines | 36 |
| 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 |
||
| 146 | public function __toString() |
||
| 147 | { |
||
| 148 | $ret = ''; |
||
| 149 | |||
| 150 | if (is_null($this->data['field']) && isset($this->data['closeParen']) && $this->data['closeParen']) { |
||
| 151 | $ret .= ")"; |
||
| 152 | return $ret; |
||
| 153 | } |
||
| 154 | |||
| 155 | switch ($this->data['operator']) { |
||
| 156 | case self::BETWEEN: |
||
| 157 | if (! isset($this->data['field']) || ! isset($this->data['low']) || ! isset($this->data['high'])) { |
||
| 158 | return ''; |
||
| 159 | } |
||
| 160 | break; |
||
| 161 | default: |
||
| 162 | if (! $this->data['field']) { |
||
| 163 | return ''; |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | if ($this->data['openParen']) { |
||
| 168 | $ret .= " ("; |
||
| 169 | } |
||
| 170 | |||
| 171 | if (! $this->data['backticks']) { |
||
| 172 | $field = $this->data['field']; |
||
| 173 | } else { |
||
| 174 | $field = "`{$this->data['field']}`"; |
||
| 175 | } |
||
| 176 | |||
| 177 | if ($this->data['operator'] == self::IN || $this->data['operator'] == self::NOT_IN) { |
||
| 178 | if (is_string($this->data['value'])) { |
||
| 179 | $ret .= " {$field} {$this->data['operator']} " . (strpos($this->data['value'], '(') !== false ? $this->data['value'] : "({$this->data['value']})"); |
||
| 180 | } elseif (is_array($this->data['value'])) { |
||
| 181 | $ret .= " {$field} {$this->data['operator']} (" . implode(",", $this->data['value']) . ")"; |
||
| 182 | } else { |
||
| 183 | return ''; |
||
| 184 | } |
||
| 185 | } elseif ($this->data['operator'] == self::BETWEEN) { |
||
| 186 | $ret .= " {$field} BETWEEN {$this->data['low']} AND {$this->data['high']}"; |
||
| 187 | } else { |
||
| 188 | $value = (is_null($this->data['value']) ? "NULL" : $this->data['value']); |
||
| 189 | |||
| 190 | if ($this->data['caseInsensitive']) { |
||
| 191 | $ret .= " LOWER({$field}) {$this->data['operator']} LOWER({$value})"; |
||
| 192 | } else { |
||
| 193 | $ret .= " {$field} {$this->data['operator']} {$value}"; |
||
| 194 | } |
||
| 195 | } |
||
| 196 | |||
| 197 | if (isset($this->data['closeParen']) && $this->data['closeParen']) { |
||
| 198 | $ret .= ")"; |
||
| 199 | } |
||
| 200 | |||
| 201 | return $ret; |
||
| 202 | } |
||
| 203 | } |