| Conditions | 14 |
| Paths | 183 |
| Total Lines | 63 |
| 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 |
||
| 49 | static function get_setting( $setting ) { |
||
| 50 | if ( ! isset( self::$valid_settings[ $setting ] ) ) { |
||
| 51 | return false; |
||
| 52 | } |
||
| 53 | |||
| 54 | if ( isset( self::$settings_cache[ $setting ] ) ) { |
||
| 55 | return self::$settings_cache[ $setting ]; |
||
| 56 | } |
||
| 57 | |||
| 58 | if ( self::is_network_setting( $setting ) ) { |
||
| 59 | if ( is_multisite() ) { |
||
| 60 | $value = get_site_option( self::SETTINGS_OPTION_PREFIX . $setting ); |
||
| 61 | } else { |
||
| 62 | // On single sites just return the default setting |
||
| 63 | $value = Defaults::get_default_setting( $setting ); |
||
| 64 | self::$settings_cache[ $setting ] = $value; |
||
| 65 | return $value; |
||
| 66 | } |
||
| 67 | } else { |
||
| 68 | $value = get_option( self::SETTINGS_OPTION_PREFIX . $setting ); |
||
| 69 | } |
||
| 70 | |||
| 71 | if ( false === $value ) { // no default value is set. |
||
| 72 | $value = Defaults::get_default_setting( $setting ); |
||
| 73 | if ( self::is_network_setting( $setting ) ) { |
||
| 74 | update_site_option( self::SETTINGS_OPTION_PREFIX . $setting, $value ); |
||
| 75 | } else { |
||
| 76 | // We set one so that it gets autoloaded |
||
| 77 | update_option( self::SETTINGS_OPTION_PREFIX . $setting, $value, true ); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | if ( is_numeric( $value ) ) { |
||
| 82 | $value = intval( $value ); |
||
| 83 | } |
||
| 84 | $default_array_value = null; |
||
| 85 | switch ( $setting ) { |
||
| 86 | case 'post_types_blacklist': |
||
| 87 | $default_array_value = Defaults::$blacklisted_post_types; |
||
|
|
|||
| 88 | break; |
||
| 89 | case 'post_meta_whitelist': |
||
| 90 | $default_array_value = Defaults::get_post_meta_whitelist(); |
||
| 91 | break; |
||
| 92 | case 'comment_meta_whitelist': |
||
| 93 | $default_array_value = Defaults::get_comment_meta_whitelist(); |
||
| 94 | break; |
||
| 95 | case 'known_importers': |
||
| 96 | $default_array_value = Defaults::get_known_importers(); |
||
| 97 | break; |
||
| 98 | } |
||
| 99 | |||
| 100 | if ( $default_array_value ) { |
||
| 101 | if ( is_array( $value ) ) { |
||
| 102 | $value = array_unique( array_merge( $value, $default_array_value ) ); |
||
| 103 | } else { |
||
| 104 | $value = $default_array_value; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | self::$settings_cache[ $setting ] = $value; |
||
| 109 | |||
| 110 | return $value; |
||
| 111 | } |
||
| 112 | |||
| 215 |
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.