| Conditions | 15 | 
| Paths | 160 | 
| Total Lines | 60 | 
| Code Lines | 27 | 
| 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 | ||
| 70 | 	public static function get_value( $config_id = '', $field_id = '' ) { | ||
| 71 | |||
| 72 | // Make sure value is defined. | ||
| 73 | $value = ''; | ||
| 74 | |||
| 75 | // This allows us to skip the $config_id argument. | ||
| 76 | // If we skip adding a $config_id, use the 'global' configuration. | ||
| 77 | 		if ( ( '' === $field_id ) && '' !== $config_id ) { | ||
| 78 | $field_id = $config_id; | ||
| 79 | $config_id = 'global'; | ||
| 80 | } | ||
| 81 | |||
| 82 | // If $config_id is empty, set it to 'global'. | ||
| 83 | $config_id = ( '' === $config_id ) ? 'global' : $config_id; | ||
| 84 | |||
| 85 | // Fallback to 'global' if $config_id is not found. | ||
| 86 | 		if ( ! isset( Kirki::$config[ $config_id ] ) ) { | ||
| 87 | $config_id = 'global'; | ||
| 88 | } | ||
| 89 | |||
| 90 | 		if ( 'theme_mod' === Kirki::$config[ $config_id ]['option_type'] ) { | ||
| 91 | |||
| 92 | // We're using theme_mods so just get the value using get_theme_mod. | ||
| 93 | $default_value = null; | ||
| 94 | 			if ( isset( Kirki::$fields[ $field_id ] ) && isset( Kirki::$fields[ $field_id ]['default'] ) ) { | ||
| 95 | $default_value = Kirki::$fields[ $field_id ]['default']; | ||
| 96 | } | ||
| 97 | $value = get_theme_mod( $field_id, $default_value ); | ||
| 98 | return apply_filters( 'kirki/values/get_value', $value, $field_id ); | ||
| 99 | } | ||
| 100 | |||
| 101 | 		if ( 'option' === Kirki::$config[ $config_id ]['option_type'] ) { | ||
| 102 | |||
| 103 | // We're using options. | ||
| 104 | 			if ( '' !== Kirki::$config[ $config_id ]['option_name'] ) { | ||
| 105 | |||
| 106 | // Options are serialized as a single option in the db. | ||
| 107 | // We'll have to get the option and then get the item from the array. | ||
| 108 | $options = get_option( Kirki::$config[ $config_id ]['option_name'] ); | ||
| 109 | |||
| 110 | 				if ( ! isset( Kirki::$fields[ $field_id ] ) && isset( Kirki::$fields[ Kirki::$config[ $config_id ]['option_name'] . '[' . $field_id . ']' ] ) ) { | ||
| 111 | $field_id = Kirki::$config[ $config_id ]['option_name'] . '[' . $field_id . ']'; | ||
| 112 | } | ||
| 113 | $setting_modified = str_replace( ']', '', str_replace( Kirki::$config[ $config_id ]['option_name'] . '[', '', $field_id ) ); | ||
| 114 | |||
| 115 | $default_value = ( isset( Kirki::$fields[ $field_id ] ) && isset( Kirki::$fields[ $field_id ]['default'] ) ) ? Kirki::$fields[ $field_id ]['default'] : ''; | ||
| 116 | $value = ( isset( $options[ $setting_modified ] ) ) ? $options[ $setting_modified ] : $default_value; | ||
| 117 | $value = maybe_unserialize( $value ); | ||
| 118 | return apply_filters( 'kirki/values/get_value', $value, $field_id ); | ||
| 119 | } | ||
| 120 | |||
| 121 | // Each option separately saved in the db. | ||
| 122 | $value = get_option( $field_id, Kirki::$fields[ $field_id ]['default'] ); | ||
| 123 | return apply_filters( 'kirki/values/get_value', $value, $field_id ); | ||
| 124 | |||
| 125 | } // End if(). | ||
| 126 | |||
| 127 | return apply_filters( 'kirki/values/get_value', $value, $field_id ); | ||
| 128 | |||
| 129 | } | ||
| 130 | |||
| 159 | 
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.