Conditions | 13 |
Paths | 9 |
Total Lines | 47 |
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 |
||
63 | function cb_explode_workouts_2( $value ) { |
||
64 | if ( '' !== $value ) { |
||
65 | $new_values = array(); |
||
66 | |||
67 | $value = explode( '|', $value ); |
||
68 | if ( ! is_array( $value ) ) { |
||
69 | $value = array( $value ); |
||
70 | } |
||
71 | if ( ! empty( $value ) ) { |
||
72 | |||
73 | foreach ( $value as $serial_string ) { |
||
74 | $serial_string = str_replace( '""', '"', $serial_string ); |
||
75 | $old_array = maybe_unserialize( $serial_string ); |
||
76 | if ( is_array( $old_array ) && ! empty( $old_array ) ) { |
||
77 | $old_values = array(); |
||
78 | |||
79 | foreach( $old_array as $old_key => $old_value ){ |
||
80 | switch( $old_key ) { |
||
81 | case 'workouttitle': |
||
82 | $old_values['name'] = $old_value; |
||
83 | break; |
||
84 | |||
85 | case 'reps': |
||
86 | $old_values['reps'] = $old_value; |
||
87 | break; |
||
88 | |||
89 | case 'video_to_workout': |
||
90 | $old_values['connected_video'] = ''; |
||
91 | break; |
||
92 | |||
93 | default: |
||
94 | break; |
||
95 | } |
||
96 | }; |
||
97 | |||
98 | if ( ! empty( $old_values ) ) { |
||
99 | $new_values[] = $old_values; |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | if ( ! empty( $new_values ) ) { |
||
105 | $value = maybe_serialize( $new_values ); |
||
106 | } |
||
107 | } |
||
108 | return $value; |
||
109 | } |
||
110 |