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 | // Sanitie colors. |
||
75 | $value['start']['color'] = ( ! isset( $value['start']['color'] ) ) ? '' : esc_attr( $value['start']['color'] ); |
||
76 | $value['end']['color'] = ( ! isset( $value['end']['color'] ) ) ? '' : esc_attr( $value['end']['color'] ); |
||
77 | |||
78 | // Sanitize positions. |
||
79 | $value['start']['position'] = ( ! isset( $value['start']['position'] ) ) ? 0 : (int) $value['start']['position']; |
||
80 | $value['start']['position'] = ( 0 > $value['start']['position'] ) ? 0 : $value['start']['position']; |
||
81 | $value['start']['position'] = ( 100 < $value['start']['position'] ) ? 100 : $value['start']['position']; |
||
82 | $value['end']['position'] = ( ! isset( $value['end']['position'] ) ) ? 0 : (int) $value['end']['position']; |
||
83 | $value['end']['position'] = ( 0 > $value['end']['position'] ) ? 0 : $value['end']['position']; |
||
84 | $value['end']['position'] = ( 100 < $value['end']['position'] ) ? 100 : $value['end']['position']; |
||
85 | |||
86 | // Sanitize angle. |
||
87 | $value['angle'] = ( ! isset( $value['angle'] ) ) ? 0 : (int) $value['angle']; |
||
88 | $value['angle'] = ( -90 > $value['angle'] ) ? -90 : $value['angle']; |
||
89 | $value['angle'] = ( 90 < $value['angle'] ) ? 90 : $value['angle']; |
||
90 | |||
91 | // Sanitize the type. |
||
92 | $value['type'] = ( ! isset( $value['type'] ) || 'linear' !== $value['type'] || 'radial' !== $value['type'] ) ? 'linear' : $value['type']; |
||
93 | |||
94 | return $value; |
||
95 | |||
96 | } |
||
97 | |||
99 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.