Conditions | 13 |
Paths | 14 |
Total Lines | 42 |
Code Lines | 21 |
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 |
||
22 | protected function process_value() { |
||
23 | |||
24 | $google_fonts_array = Kirki_Fonts::get_google_fonts(); |
||
25 | $backup_fonts = Kirki_Fonts::get_backup_fonts(); |
||
26 | |||
27 | $family = $this->value; |
||
28 | $backup = ''; |
||
29 | if ( is_array( $this->value ) && isset( $this->value[0] ) && isset( $this->value[1] ) ) { |
||
30 | $family = $this->value[0]; |
||
31 | $backup = $this->value[1]; |
||
32 | } |
||
33 | |||
34 | // Make sure the value is a string. |
||
35 | // If not, then early exit. |
||
36 | if ( ! is_string( $family ) ) { |
||
37 | return; |
||
38 | } |
||
39 | |||
40 | // Hack for standard fonts. |
||
41 | $family = str_replace( '"', '"', $family ); |
||
42 | |||
43 | // Add backup font. |
||
44 | if ( Kirki_Fonts::is_google_font( $family ) ) { |
||
45 | |||
46 | if ( '' === $backup && isset( $google_fonts_array[ $family ] ) && isset( $backup_fonts[ $google_fonts_array[ $family ]['category'] ] ) ) { |
||
47 | $backup = $backup_fonts[ $google_fonts_array[ $family ]['category'] ]; |
||
48 | } |
||
49 | |||
50 | // Add double quotes if needed. |
||
51 | if ( false !== strpos( $family, ' ' ) && false === strpos( $family, '"' ) ) { |
||
52 | $this->value = '"' . $family . '", ' . $backup; |
||
53 | return; |
||
54 | } |
||
55 | $this->value = $family . ', ' . $backup; |
||
56 | return; |
||
57 | } |
||
58 | |||
59 | // Add double quotes if needed. |
||
60 | if ( false !== strpos( $family, ' ' ) && false === strpos( $family, '"' ) ) { |
||
61 | $this->value = '"' . $family . '"'; |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 |