Conditions | 13 |
Paths | 147 |
Total Lines | 60 |
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 |
||
48 | static function get_setting( $setting ) { |
||
49 | if ( ! isset( self::$valid_settings[ $setting ] ) ) { |
||
50 | return false; |
||
51 | } |
||
52 | |||
53 | if ( isset( self::$settings_cache[ $setting ] ) ) { |
||
54 | return self::$settings_cache[ $setting ]; |
||
55 | } |
||
56 | |||
57 | if ( self::is_network_setting( $setting ) ) { |
||
58 | if ( is_multisite() ) { |
||
59 | $value = get_site_option( self::SETTINGS_OPTION_PREFIX . $setting ); |
||
60 | } else { |
||
61 | // On single sites just return the default setting |
||
62 | $value = Jetpack_Sync_Defaults::get_default_setting( $setting ); |
||
63 | self::$settings_cache[ $setting ] = $value; |
||
64 | return $value; |
||
65 | } |
||
66 | } else { |
||
67 | $value = get_option( self::SETTINGS_OPTION_PREFIX . $setting ); |
||
68 | } |
||
69 | |||
70 | if ( false === $value ) { // no default value is set. |
||
71 | $value = Jetpack_Sync_Defaults::get_default_setting( $setting ); |
||
72 | if ( self::is_network_setting( $setting ) ) { |
||
73 | update_site_option( self::SETTINGS_OPTION_PREFIX . $setting, $value ); |
||
74 | } else { |
||
75 | // We set one so that it gets autoloaded |
||
76 | update_option( self::SETTINGS_OPTION_PREFIX . $setting, $value, true ); |
||
77 | } |
||
78 | } |
||
79 | |||
80 | if ( is_numeric( $value ) ) { |
||
81 | $value = intval( $value ); |
||
82 | } |
||
83 | $default_array_value = null; |
||
84 | switch ( $setting ) { |
||
85 | case 'post_types_blacklist': |
||
86 | $default_array_value = Jetpack_Sync_Defaults::$blacklisted_post_types; |
||
|
|||
87 | break; |
||
88 | case 'post_meta_whitelist': |
||
89 | $default_array_value = Jetpack_Sync_Defaults::get_post_meta_whitelist(); |
||
90 | break; |
||
91 | case 'comment_meta_whitelist': |
||
92 | $default_array_value = Jetpack_Sync_Defaults::get_comment_meta_whitelist(); |
||
93 | break; |
||
94 | } |
||
95 | |||
96 | if ( $default_array_value ) { |
||
97 | if ( is_array( $value ) ) { |
||
98 | $value = array_unique( array_merge( $value, $default_array_value ) ); |
||
99 | } else { |
||
100 | $value = $default_array_value; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | self::$settings_cache[ $setting ] = $value; |
||
105 | |||
106 | return $value; |
||
107 | } |
||
108 | |||
212 |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.