Conditions | 10 |
Paths | 50 |
Total Lines | 45 |
Code Lines | 30 |
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 |
||
42 | static function get_setting( $setting ) { |
||
43 | if ( ! isset( self::$valid_settings[ $setting ] ) ) { |
||
44 | return false; |
||
45 | } |
||
46 | |||
47 | if ( isset( self::$settings_cache[ $setting ] ) ) { |
||
48 | return self::$settings_cache[ $setting ]; |
||
49 | } |
||
50 | |||
51 | $value = get_option( self::SETTINGS_OPTION_PREFIX . $setting ); |
||
52 | |||
53 | if ( false === $value ) { |
||
54 | $default_name = "default_$setting"; // e.g. default_dequeue_max_bytes |
||
55 | $value = Jetpack_Sync_Defaults::$$default_name; |
||
56 | update_option( self::SETTINGS_OPTION_PREFIX . $setting, $value, true ); |
||
57 | } |
||
58 | |||
59 | if ( is_numeric( $value ) ) { |
||
60 | $value = intval( $value ); |
||
61 | } |
||
62 | $default_array_value = null; |
||
63 | switch( $setting ) { |
||
64 | case 'post_types_blacklist': |
||
65 | $default_array_value = Jetpack_Sync_Defaults::$blacklisted_post_types; |
||
66 | break; |
||
67 | case 'post_meta_whitelist': |
||
68 | $default_array_value = Jetpack_Sync_Defaults::$post_meta_whitelist; |
||
69 | break; |
||
70 | case 'comment_meta_whitelist': |
||
71 | $default_array_value = Jetpack_Sync_Defaults::$comment_meta_whitelist; |
||
72 | break; |
||
73 | } |
||
74 | |||
75 | if ( $default_array_value ) { |
||
76 | if ( is_array( $value ) ) { |
||
77 | $value = array_unique( array_merge( $value, $default_array_value ) ); |
||
78 | } else { |
||
79 | $value = $default_array_value; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | self::$settings_cache[ $setting ] = $value; |
||
84 | |||
85 | return $value; |
||
86 | } |
||
87 | |||
163 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.