| Conditions | 14 |
| Paths | 15 |
| Total Lines | 29 |
| 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 |
||
| 75 | public function clean() |
||
| 76 | { |
||
| 77 | $sanitized = ''; |
||
| 78 | |||
| 79 | if (in_array($this->type, ['color', 'radio', 'select'], true)) { |
||
| 80 | $sanitized = $this->sanitize_random($this->data); |
||
| 81 | } elseif (in_array($this->type, ['date', 'datetime', 'datetime-local', 'time', 'week'], true)) { |
||
| 82 | $sanitized = $this->sanitize_wrapper($this->data, 'strtotime'); |
||
| 83 | } elseif (in_array($this->type, ['number', 'range'], true)) { |
||
| 84 | $sanitized = $this->sanitize_wrapper($this->data, 'intval'); |
||
| 85 | } elseif (in_array($this->type, ['hidden', 'month', 'text'], true)) { |
||
| 86 | $sanitized = $this->sanitize_wrapper($this->data, 'sanitize_text_field'); |
||
| 87 | } elseif ($this->type == 'checkbox') { |
||
| 88 | $sanitized = (isset($this->data) && ! is_null($this->data) ? true : false); |
||
| 89 | } elseif ($this->type == 'editor') { |
||
| 90 | $sanitized = wp_kses_post($this->data); |
||
|
|
|||
| 91 | } elseif ($this->type == 'email') { |
||
| 92 | $sanitized = $this->sanitize_wrapper($this->data, 'sanitize_email'); |
||
| 93 | } elseif ($this->type == 'file') { |
||
| 94 | $sanitized = $this->sanitize_wrapper($this->data, 'sanitize_file_name'); |
||
| 95 | } elseif ($this->type == 'tel') { |
||
| 96 | $sanitized = $this->sanitize_phone($this->data); |
||
| 97 | } elseif ($this->type == 'textarea') { |
||
| 98 | $sanitized = $this->sanitize_wrapper($this->data, 'esc_textarea'); |
||
| 99 | } elseif ($this->type == 'url') { |
||
| 100 | $sanitized = $this->sanitize_wrapper($this->data, 'esc_url'); |
||
| 101 | } |
||
| 102 | |||
| 103 | return $sanitized; |
||
| 104 | } |
||
| 182 |