Conditions | 33 |
Paths | 159 |
Total Lines | 96 |
Code Lines | 47 |
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 |
||
111 | public function generate_google_font( $args ) { |
||
112 | |||
113 | // Process typography fields. |
||
114 | if ( isset( $args['type'] ) && 'kirki-typography' === $args['type'] ) { |
||
115 | |||
116 | // Get the value. |
||
117 | $value = Kirki_Values::get_sanitized_field_value( $args ); |
||
118 | |||
119 | // If we don't have a font-family then we can skip this. |
||
120 | if ( ! isset( $value['font-family'] ) ) { |
||
121 | return; |
||
122 | } |
||
123 | |||
124 | // If not a google-font, then we can skip this. |
||
125 | if ( ! Kirki_Fonts::is_google_font( $value['font-family'] ) ) { |
||
126 | return; |
||
127 | } |
||
128 | |||
129 | // Set a default value for variants. |
||
130 | if ( ! isset( $value['variant'] ) ) { |
||
131 | $value['variant'] = 'regular'; |
||
132 | } |
||
133 | if ( isset( $value['subsets'] ) ) { |
||
134 | |||
135 | // Add the subset directly to the array of subsets in the Kirki_GoogleFonts_Manager object. |
||
136 | // Subsets must be applied to ALL fonts if possible. |
||
137 | if ( ! is_array( $value['subsets'] ) ) { |
||
138 | $this->subsets[] = $value['subsets']; |
||
139 | } else { |
||
140 | foreach ( $value['subsets'] as $subset ) { |
||
141 | $this->subsets[] = $subset; |
||
142 | } |
||
143 | } |
||
144 | } |
||
145 | |||
146 | // Add the requested google-font. |
||
147 | if ( ! isset( $this->fonts[ $value['font-family'] ] ) ) { |
||
148 | $this->fonts[ $value['font-family'] ] = array(); |
||
149 | } |
||
150 | if ( ! in_array( $value['variant'], $this->fonts[ $value['font-family'] ], true ) ) { |
||
151 | $this->fonts[ $value['font-family'] ][] = $value['variant']; |
||
152 | } |
||
153 | // Are we force-loading all variants? |
||
154 | if ( true === self::$force_load_all_variants ) { |
||
155 | $all_variants = Kirki_Fonts::get_all_variants(); |
||
156 | $args['choices']['variant'] = array_keys( $all_variants ); |
||
157 | } |
||
158 | |||
159 | if ( ! empty( $args['choices']['variant'] ) && is_array( $args['choices']['variant'] ) ) { |
||
160 | foreach ( $args['choices']['variant'] as $extra_variant ) { |
||
161 | $this->fonts[ $value['font-family'] ][] = $extra_variant; |
||
162 | } |
||
163 | } |
||
164 | } else { |
||
165 | |||
166 | // Process non-typography fields. |
||
167 | if ( isset( $args['output'] ) && is_array( $args['output'] ) ) { |
||
168 | foreach ( $args['output'] as $output ) { |
||
169 | |||
170 | // If we don't have a typography-related output argument we can skip this. |
||
171 | if ( ! isset( $output['property'] ) || ! in_array( $output['property'], array( 'font-family', 'font-weight', 'font-subset', 'subset', 'subsets' ), true ) ) { |
||
172 | continue; |
||
173 | } |
||
174 | |||
175 | // Get the value. |
||
176 | $value = Kirki_Values::get_sanitized_field_value( $args ); |
||
177 | |||
178 | if ( is_string( $value ) ) { |
||
179 | if ( 'font-family' === $output['property'] ) { |
||
180 | if ( ! array_key_exists( $value, $this->fonts ) ) { |
||
181 | $this->fonts[ $value ] = array(); |
||
182 | } |
||
183 | } elseif ( 'font-weight' === $output['property'] ) { |
||
184 | foreach ( $this->fonts as $font => $variants ) { |
||
185 | if ( ! in_array( $value, $variants, true ) ) { |
||
186 | $this->fonts[ $font ][] = $value; |
||
187 | } |
||
188 | } |
||
189 | } elseif ( 'font-subset' === $output['property'] || 'subset' === $output['property'] || 'subsets' === $output['property'] ) { |
||
190 | if ( ! is_array( $value ) ) { |
||
191 | if ( ! in_array( $value, $this->subsets, true ) ) { |
||
192 | $this->subsets[] = $value; |
||
193 | } |
||
194 | } else { |
||
195 | foreach ( $value as $subset ) { |
||
196 | if ( ! in_array( $subset, $this->subsets, true ) ) { |
||
197 | $this->subsets[] = $subset; |
||
198 | } |
||
199 | } |
||
200 | } |
||
201 | } |
||
202 | } |
||
203 | } // End foreach(). |
||
204 | } // End if(). |
||
205 | } // End if(). |
||
206 | } |
||
207 | |||
270 |