Conditions | 14 |
Paths | 259 |
Total Lines | 16 |
Code Lines | 11 |
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 |
||
98 | public function sanitize( $value ) { |
||
99 | if ( isset( $this->choices['save_as'] ) && 'array' === $this->choices['save_as'] ) { |
||
100 | return array( |
||
101 | 'id' => ( isset( $value['id'] ) && '' !== $value['id'] ) ? (int) $value['id'] : '', |
||
102 | 'url' => ( isset( $value['url'] ) && '' !== $value['url'] ) ? esc_url_raw( $value['url'] ) : '', |
||
103 | 'width' => ( isset( $value['width'] ) && '' !== $value['width'] ) ? (int) $value['width'] : '', |
||
104 | 'height' => ( isset( $value['height'] ) && '' !== $value['height'] ) ? (int) $value['height'] : '', |
||
105 | ); |
||
106 | } |
||
107 | if ( isset( $this->choices['save_as'] ) && 'id' === $this->choices['save_as'] ) { |
||
108 | return absint( $value ); |
||
109 | } |
||
110 | if ( is_string( $value ) ) { |
||
111 | return esc_url_raw( $value ); |
||
112 | } |
||
113 | return $value; |
||
114 | } |
||
116 |