| Conditions | 27 |
| Paths | 76 |
| Total Lines | 71 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 113 | public function generate_google_font( $args ) { |
||
| 114 | |||
| 115 | global $wp_customize; |
||
| 116 | |||
| 117 | // Process typography fields. |
||
| 118 | if ( isset( $args['type'] ) && 'kirki-typography' === $args['type'] ) { |
||
| 119 | |||
| 120 | // Get the value. |
||
| 121 | $value = Kirki_Values::get_sanitized_field_value( $args ); |
||
| 122 | |||
| 123 | if ( isset( $value['downloadFont'] ) && $value['downloadFont'] ) { |
||
| 124 | $this->hosted_fonts[] = $value['font-family']; |
||
| 125 | } |
||
| 126 | |||
| 127 | // If we don't have a font-family then we can skip this. |
||
| 128 | if ( ! $wp_customize && ( ! isset( $value['font-family'] ) || in_array( $value['font-family'], $this->hosted_fonts ) ) ) { |
||
| 129 | return; |
||
| 130 | } |
||
| 131 | |||
| 132 | // If not a google-font, then we can skip this. |
||
| 133 | if ( ! Kirki_Fonts::is_google_font( $value['font-family'] ) ) { |
||
| 134 | return; |
||
| 135 | } |
||
| 136 | |||
| 137 | // Set a default value for variants. |
||
| 138 | if ( ! isset( $value['variant'] ) ) { |
||
| 139 | $value['variant'] = 'regular'; |
||
| 140 | } |
||
| 141 | |||
| 142 | // Add the requested google-font. |
||
| 143 | if ( ! isset( $this->fonts[ $value['font-family'] ] ) ) { |
||
| 144 | $this->fonts[ $value['font-family'] ] = array(); |
||
| 145 | } |
||
| 146 | if ( ! in_array( $value['variant'], $this->fonts[ $value['font-family'] ], true ) ) { |
||
| 147 | $this->fonts[ $value['font-family'] ][] = $value['variant']; |
||
| 148 | } |
||
| 149 | // Are we force-loading all variants? |
||
| 150 | if ( true === self::$force_load_all_variants ) { |
||
| 151 | $all_variants = Kirki_Fonts::get_all_variants(); |
||
| 152 | $args['choices']['variant'] = array_keys( $all_variants ); |
||
| 153 | } |
||
| 154 | |||
| 155 | if ( ! empty( $args['choices']['variant'] ) && is_array( $args['choices']['variant'] ) ) { |
||
| 156 | foreach ( $args['choices']['variant'] as $extra_variant ) { |
||
| 157 | $this->fonts[ $value['font-family'] ][] = $extra_variant; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | return; |
||
| 161 | } |
||
| 162 | |||
| 163 | // Process non-typography fields. |
||
| 164 | if ( isset( $args['output'] ) && is_array( $args['output'] ) ) { |
||
| 165 | foreach ( $args['output'] as $output ) { |
||
| 166 | |||
| 167 | // If we don't have a typography-related output argument we can skip this. |
||
| 168 | if ( ! isset( $output['property'] ) || ! in_array( $output['property'], array( 'font-family', 'font-weight' ), true ) ) { |
||
| 169 | continue; |
||
| 170 | } |
||
| 171 | |||
| 172 | // Get the value. |
||
| 173 | $value = Kirki_Values::get_sanitized_field_value( $args ); |
||
| 174 | |||
| 175 | if ( is_string( $value ) ) { |
||
| 176 | if ( 'font-family' === $output['property'] ) { |
||
| 177 | if ( ! array_key_exists( $value, $this->fonts ) ) { |
||
| 178 | $this->fonts[ $value ] = array(); |
||
| 179 | } |
||
| 180 | } elseif ( 'font-weight' === $output['property'] ) { |
||
| 181 | foreach ( $this->fonts as $font => $variants ) { |
||
| 182 | if ( ! in_array( $value, $variants, true ) ) { |
||
| 183 | $this->fonts[ $font ][] = $value; |
||
| 184 | } |
||
| 264 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..