| Conditions | 10 | 
| Paths | 12 | 
| Total Lines | 38 | 
| Code Lines | 12 | 
| 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 | ||
| 77 | 	public static function get_variables() { | ||
| 78 | |||
| 79 | $variables = array(); | ||
| 80 | |||
| 81 | // Loop through all fields. | ||
| 82 | 		foreach ( Kirki::$fields as $field ) { | ||
| 83 | |||
| 84 | // Check if we have variables for this field. | ||
| 85 | 			if ( isset( $field['variables'] ) && $field['variables'] && ! empty( $field['variables'] ) ) { | ||
| 86 | |||
| 87 | // Loop through the array of variables. | ||
| 88 | 				foreach ( $field['variables'] as $field_variable ) { | ||
| 89 | |||
| 90 | // Is the variable ['name'] defined? If yes, then we can proceed. | ||
| 91 | 					if ( isset( $field_variable['name'] ) ) { | ||
| 92 | |||
| 93 | // Sanitize the variable name. | ||
| 94 | $variable_name = esc_attr( $field_variable['name'] ); | ||
| 95 | |||
| 96 | // Do we have a callback function defined? If not then set $variable_callback to false. | ||
| 97 | $variable_callback = ( isset( $field_variable['callback'] ) && is_callable( $field_variable['callback'] ) ) ? $field_variable['callback'] : false; | ||
| 98 | |||
| 99 | // If we have a variable_callback defined then get the value of the option | ||
| 100 | // and run it through the callback function. | ||
| 101 | // If no callback is defined (false) then just get the value. | ||
| 102 | $variables[ $variable_name ] = Kirki_Values::get_value( $field['settings'] ); | ||
| 103 | 						if ( $variable_callback ) { | ||
| 104 | $variables[ $variable_name ] = call_user_func( $field_variable['callback'], Kirki_Values::get_value( $field['settings'] ) ); | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | 		// Pass the variables through a filter ('kirki/variable') and return the array of variables. | ||
| 112 | return apply_filters( 'kirki/variable', $variables ); | ||
| 113 | |||
| 114 | } | ||
| 115 | |||
| 159 |