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