| Conditions | 14 |
| Paths | 259 |
| Total Lines | 18 |
| Code Lines | 12 |
| 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 |
||
| 65 | public function sanitize( $value ) { |
||
| 66 | |||
| 67 | if ( isset( $this->choices['save_as'] ) && 'array' === $this->choices['save_as'] ) { |
||
| 68 | return array( |
||
| 69 | 'id' => ( isset( $value['id'] ) && '' !== $value['id'] ) ? (int) $value['id'] : '', |
||
| 70 | 'url' => ( isset( $value['url'] ) && '' !== $value['url'] ) ? esc_url_raw( $value['url'] ) : '', |
||
| 71 | 'width' => ( isset( $value['width'] ) && '' !== $value['width'] ) ? (int) $value['width'] : '', |
||
| 72 | 'height' => ( isset( $value['height'] ) && '' !== $value['height'] ) ? (int) $value['height'] : '', |
||
| 73 | ); |
||
| 74 | } |
||
| 75 | if ( isset( $this->choices['save_as'] ) && 'id' === $this->choices['save_as'] ) { |
||
| 76 | return absint( $value ); |
||
| 77 | } |
||
| 78 | if ( is_string( $value ) ) { |
||
| 79 | return esc_url_raw( $value ); |
||
| 80 | } |
||
| 81 | return $value; |
||
| 82 | } |
||
| 83 | } |
||
| 84 |