Conditions | 18 |
Paths | > 20000 |
Total Lines | 32 |
Code Lines | 17 |
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 = null ) { |
||
66 | |||
67 | // Make sure value in an array. |
||
68 | $value = ( ! is_array( $value ) ) ? array() : $value; |
||
69 | |||
70 | // Make sure start & end values are arrays. |
||
71 | $value['start'] = ( ! isset( $value['start'] ) ) ? array() : $value['start']; |
||
72 | $value['end'] = ( ! isset( $value['end'] ) ) ? array() : $value['end']; |
||
73 | |||
74 | foreach ( array( 'start', 'end' ) as $context ) { |
||
75 | |||
76 | // Sanitize colors. |
||
77 | if ( ! isset( $value[ $context ]['color'] ) ) { |
||
78 | $value[ $context ]['color'] = ''; |
||
79 | } |
||
80 | $value[ $context ]['color'] = esc_attr( $value[ $context ]['color'] ); |
||
|
|||
81 | |||
82 | // Sanitize positions. |
||
83 | if ( ! isset( $value[ $context ]['position'] ) ) { |
||
84 | $value[ $context ]['position'] = 0; |
||
85 | }; |
||
86 | $value[ $context ]['position'] = (int) $value[ $context ]['position']; |
||
87 | $value[ $context ]['position'] = max( min( $value[ $context ]['position'], 100 ), 0 ); |
||
88 | } |
||
89 | |||
90 | // Sanitize angle. |
||
91 | if ( ! isset( $value['angle'] ) ) { |
||
92 | $value['angle'] = 0; |
||
93 | } |
||
94 | $value['angle'] = (int) $value['angle']; |
||
95 | $value['angle'] = max( min( $value['angle'], 90 ), -90 ) |
||
96 | |||
97 | // Sanitize the type. |
||
105 |