Conditions | 28 |
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 |
||
112 | public function generate_google_font( $args ) { |
||
113 | global $wp_customize; |
||
114 | |||
115 | // Process typography fields. |
||
116 | if ( isset( $args['type'] ) && 'kirki-typography' === $args['type'] ) { |
||
117 | |||
118 | // Get the value. |
||
119 | $value = Kirki_Values::get_sanitized_field_value( $args ); |
||
120 | |||
121 | if ( isset( $value['downloadFont'] ) && $value['downloadFont'] ) { |
||
122 | $this->hosted_fonts[] = $value['font-family']; |
||
123 | } |
||
124 | |||
125 | // If we don't have a font-family then we can skip this. |
||
126 | if ( ! $wp_customize && ( ! isset( $value['font-family'] ) || in_array( $value['font-family'], $this->hosted_fonts, true ) ) ) { |
||
127 | return; |
||
128 | } |
||
129 | |||
130 | // If not a google-font, then we can skip this. |
||
131 | if ( ! isset( $value['font-family'] ) || ! Kirki_Fonts::is_google_font( $value['font-family'] ) ) { |
||
132 | return; |
||
133 | } |
||
134 | |||
135 | // Set a default value for variants. |
||
136 | if ( ! isset( $value['variant'] ) ) { |
||
137 | $value['variant'] = 'regular'; |
||
138 | } |
||
139 | |||
140 | // Add the requested google-font. |
||
141 | if ( ! isset( $this->fonts[ $value['font-family'] ] ) ) { |
||
142 | $this->fonts[ $value['font-family'] ] = array(); |
||
143 | } |
||
144 | if ( ! in_array( $value['variant'], $this->fonts[ $value['font-family'] ], true ) ) { |
||
145 | $this->fonts[ $value['font-family'] ][] = $value['variant']; |
||
146 | } |
||
147 | |||
148 | // Are we force-loading all variants? |
||
149 | if ( true === self::$force_load_all_variants ) { |
||
150 | $all_variants = Kirki_Fonts::get_all_variants(); |
||
151 | $args['choices']['variant'] = array_keys( $all_variants ); |
||
152 | } |
||
153 | |||
154 | if ( ! empty( $args['choices']['variant'] ) && is_array( $args['choices']['variant'] ) ) { |
||
155 | foreach ( $args['choices']['variant'] as $extra_variant ) { |
||
156 | $this->fonts[ $value['font-family'] ][] = $extra_variant; |
||
157 | } |
||
158 | } |
||
159 | return; |
||
160 | } |
||
161 | |||
162 | // Process non-typography fields. |
||
163 | if ( isset( $args['output'] ) && is_array( $args['output'] ) ) { |
||
164 | foreach ( $args['output'] as $output ) { |
||
165 | |||
166 | // If we don't have a typography-related output argument we can skip this. |
||
167 | if ( ! isset( $output['property'] ) || ! in_array( $output['property'], array( 'font-family', 'font-weight' ), true ) ) { |
||
168 | continue; |
||
169 | } |
||
170 | |||
171 | // Get the value. |
||
172 | $value = Kirki_Values::get_sanitized_field_value( $args ); |
||
173 | |||
174 | if ( is_string( $value ) ) { |
||
175 | if ( 'font-family' === $output['property'] ) { |
||
176 | if ( ! array_key_exists( $value, $this->fonts ) ) { |
||
177 | $this->fonts[ $value ] = array(); |
||
178 | } |
||
179 | } elseif ( 'font-weight' === $output['property'] ) { |
||
180 | foreach ( $this->fonts as $font => $variants ) { |
||
181 | if ( ! in_array( $value, $variants, true ) ) { |
||
182 | $this->fonts[ $font ][] = $value; |
||
183 | } |
||
263 |