Conditions | 10 |
Paths | 12 |
Total Lines | 34 |
Code Lines | 20 |
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 |
||
4 | function callback( $path = '', $site_id = 0 ) { |
||
5 | // Switch to the given blog. |
||
6 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $site_id ) ); |
||
7 | if ( is_wp_error( $blog_id ) ) { |
||
8 | return $blog_id; |
||
9 | } |
||
10 | |||
11 | if ( ! current_user_can( 'edit_theme_options' ) ) { |
||
12 | return new WP_Error( 'unauthorized', 'User is not authorized to access logo settings', 403 ); |
||
13 | } |
||
14 | |||
15 | if ( strpos( $path, '/delete' ) ) { |
||
16 | delete_option( 'site_logo' ); |
||
17 | return array(); |
||
18 | } |
||
19 | |||
20 | $args = $this->input(); |
||
21 | $logo_settings = $this->get_current_settings(); |
||
22 | if ( empty( $args ) || ! is_array( $args ) ) { |
||
23 | return $logo_settings; |
||
24 | } |
||
25 | |||
26 | if ( isset( $args['id'] ) ) { |
||
27 | $logo_settings['id'] = intval( $args['id'], 10 ); |
||
28 | } |
||
29 | if ( isset( $args['url'] ) ) { |
||
30 | $logo_settings['url'] = $args['url']; |
||
31 | } |
||
32 | if ( isset( $args['url'] ) || isset( $args['id'] ) ) { |
||
33 | update_option( 'site_logo', $logo_settings ); |
||
34 | } |
||
35 | |||
36 | return $this->get_current_settings(); |
||
37 | } |
||
38 | |||
48 |