Conditions | 10 |
Paths | 8 |
Total Lines | 35 |
Code Lines | 22 |
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 |
||
66 | function callback( $path = '', $blog_id = 0 ) { |
||
67 | // Switch to the given blog. |
||
68 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
||
69 | if ( is_wp_error( $blog_id ) ) { |
||
70 | return $blog_id; |
||
71 | } |
||
72 | |||
73 | if ( ! current_user_can( 'edit_theme_options' ) ) { |
||
74 | return new WP_Error( 'unauthorized', 'User is not authorized to access widgets', 403 ); |
||
75 | } |
||
76 | |||
77 | jetpack_require_lib( 'widgets' ); |
||
78 | $args = $this->input( false, false ); // Don't filter the input |
||
79 | if ( empty( $args ) || ! is_array( $args ) ) { |
||
80 | return new WP_Error( 'no_data', 'No data was provided.', 400 ); |
||
81 | } |
||
82 | if ( isset( $args['widgets'] ) || ! empty( $args['widgets'] ) ) { |
||
83 | $widgets = Jetpack_Widgets::activate_widgets( $args['widgets'] ); |
||
84 | if ( is_wp_error( $widgets ) ) { |
||
85 | return $widgets; |
||
86 | } |
||
87 | return array( 'widgets' => $widgets ); |
||
88 | } |
||
89 | if ( ! isset( $args['id_base'] ) ) { |
||
90 | return new WP_Error( 'missing_data', 'The data you provided was not accurate.', 400 ); |
||
91 | } |
||
92 | |||
93 | if ( empty( $args['sidebar'] ) ) { |
||
94 | $active_sidebars = Jetpack_Widgets::get_active_sidebars(); |
||
95 | reset( $active_sidebars ); |
||
96 | $args['sidebar'] = key( $active_sidebars ); |
||
97 | } |
||
98 | |||
99 | return Jetpack_Widgets::activate_widget( $args['id_base'], $args['sidebar'], $args['position'], $args['settings'] ); |
||
100 | } |
||
101 | |||
104 |