| Conditions | 21 |
| Paths | 33 |
| Total Lines | 75 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 19 | public static function generate_google_fonts( $field ) { |
||
| 20 | /** |
||
| 21 | * Process typography fields |
||
| 22 | */ |
||
| 23 | if ( isset( $field['type'] ) && 'typography' == $field['type'] ) { |
||
| 24 | // Get the value |
||
| 25 | $value = Kirki_Values::get_sanitized_field_value( $field ); |
||
| 26 | // If we don't have a font-family then we can skip this. |
||
| 27 | if ( ! isset( $value['font-family'] ) ) { |
||
| 28 | return; |
||
| 29 | } |
||
| 30 | // Set a default value for font-weight |
||
| 31 | if ( ! isset( $value['font-weight'] ) ) { |
||
| 32 | $value['font-weight'] = 400; |
||
| 33 | } |
||
| 34 | if ( isset( $value['subset'] ) ) { |
||
| 35 | // Add the subset directly to the array of subsets |
||
| 36 | // in the Kirki_GoogleFonts_Manager object. |
||
| 37 | if ( ! is_array( $value['subset'] ) ) { |
||
| 38 | Kirki_GoogleFonts_Manager::$subsets[] = $value['subset']; |
||
| 39 | } else { |
||
| 40 | foreach ( $value['subset'] as $subset ) { |
||
| 41 | Kirki_GoogleFonts_Manager::$subsets[] = $subset; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | // Get the font-style |
||
| 46 | if ( ! isset( $value['font-style'] ) ) { |
||
| 47 | $value['font-style'] = 'regular'; |
||
| 48 | } |
||
| 49 | // Add the requested google-font |
||
| 50 | Kirki_GoogleFonts_Manager::add_font( $value['font-family'], $value['font-weight'], $value['font-style'] ); |
||
| 51 | // Add font-weight 700 so that bold works for all fonts |
||
| 52 | Kirki_GoogleFonts_Manager::add_font( $value['font-family'], 700, $value['font-style'] ); |
||
| 53 | // Any additional font-weights we may need |
||
| 54 | foreach ( Kirki_GoogleFonts_Manager::$font_weights as $font_weight ) { |
||
| 55 | Kirki_GoogleFonts_Manager::add_font( $value['font-family'], 700, $value['font-style'] ); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Process non-typography fields |
||
| 61 | */ |
||
| 62 | else { |
||
| 63 | if ( isset( $field['output'] ) && is_array( $field['output'] ) ) { |
||
| 64 | foreach ( $field['output'] as $output ) { |
||
| 65 | // If we don't have a typography-related output argument we can skip this. |
||
| 66 | if ( ! isset( $output['property'] ) || ! in_array( $output['property'], array( 'font-family', 'font-weight', 'font-subset', 'subset', 'font-style' ) ) ) { |
||
| 67 | continue; |
||
| 68 | } |
||
| 69 | // Get the value |
||
| 70 | $value = Kirki_Values::get_sanitized_field_value( $field ); |
||
| 71 | |||
| 72 | // font-family |
||
| 73 | if ( 'font-family' == $output['property'] ) { |
||
| 74 | Kirki_GoogleFonts_Manager::add_font( $value ); |
||
| 75 | } |
||
| 76 | // font-weight |
||
| 77 | elseif ( 'font-weight' == $output['property'] ) { |
||
| 78 | Kirki_GoogleFonts_Manager::$font_weights[] = $value; |
||
| 79 | } |
||
| 80 | // subsets |
||
| 81 | elseif ( 'font-subset' == $output['property'] || 'subset' == $output['property'] ) { |
||
| 82 | if ( ! is_array( $value ) ) { |
||
| 83 | Kirki_GoogleFonts_Manager::$subsets[] = $value; |
||
| 84 | } else { |
||
| 85 | foreach ( $value as $subset ) { |
||
| 86 | Kirki_GoogleFonts_Manager::$subsets[] = $subset; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 96 |