Conditions | 22 |
Paths | 896 |
Total Lines | 69 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
24 | protected function process_output( $output, $value ) { |
||
25 | $output['media_query'] = ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global'; |
||
26 | $output['element'] = ( isset( $output['element'] ) ) ? $output['element'] : 'body'; |
||
27 | $output['prefix'] = ( isset( $output['prefix'] ) ) ? $output['prefix'] : ''; |
||
28 | $output['suffix'] = ( isset( $output['suffix'] ) ) ? $output['suffix'] : ''; |
||
29 | |||
30 | $value = Kirki_Field_Typography::sanitize( $value ); |
||
31 | |||
32 | $properties = array( |
||
33 | 'font-family', |
||
34 | 'font-size', |
||
35 | 'variant', |
||
36 | 'font-weight', |
||
37 | 'font-style', |
||
38 | 'letter-spacing', |
||
39 | 'word-spacing', |
||
40 | 'line-height', |
||
41 | 'text-align', |
||
42 | 'text-transform', |
||
43 | 'text-decoration', |
||
44 | 'color', |
||
45 | ); |
||
46 | |||
47 | foreach ( $properties as $property ) { |
||
48 | |||
49 | // Early exit if the value is not in the defaults. |
||
50 | if ( ! isset( $this->field['default'][ $property ] ) ) { |
||
51 | continue; |
||
52 | } |
||
53 | |||
54 | // Early exit if the value is not saved in the values. |
||
55 | if ( ! isset( $value[ $property ] ) || ! $value[ $property ] ) { |
||
56 | continue; |
||
57 | } |
||
58 | |||
59 | // Early exit if we use "choice" but not for this property. |
||
60 | if ( isset( $output['choice'] ) && $output['choice'] !== $property ) { |
||
61 | continue; |
||
62 | } |
||
63 | |||
64 | // Take care of variants. |
||
65 | if ( 'variant' === $property && isset( $value['variant'] ) && ! empty( $value['variant'] ) ) { |
||
66 | |||
67 | // Get the font_weight. |
||
68 | $font_weight = str_replace( 'italic', '', $value['variant'] ); |
||
69 | $font_weight = ( in_array( $font_weight, array( '', 'regular' ), true ) ) ? '400' : $font_weight; |
||
70 | |||
71 | // Is this italic? |
||
72 | $is_italic = ( false !== strpos( $value['variant'], 'italic' ) ); |
||
73 | $this->styles[ $output['media_query'] ][ $output['element'] ]['font-weight'] = $font_weight; |
||
74 | if ( $is_italic ) { |
||
75 | $this->styles[ $output['media_query'] ][ $output['element'] ]['font-style'] = 'italic'; |
||
76 | } |
||
77 | continue; |
||
78 | } |
||
79 | |||
80 | $property_value = $this->process_property_value( $property, $value[ $property ] ); |
||
81 | if ( 'font-family' === $property ) { |
||
82 | $value['font-backup'] = ( isset( $value['font-backup'] ) ) ? $value['font-backup'] : ''; |
||
83 | $property_value = $this->process_property_value( |
||
84 | $property, array( |
||
|
|||
85 | $value['font-family'], |
||
86 | $value['font-backup'], |
||
87 | ) |
||
88 | ); |
||
89 | } |
||
90 | $property = ( isset( $output['choice'] ) && isset( $output['property'] ) ) ? $output['property'] : $property; |
||
91 | $property_value = ( is_array( $property_value ) && isset( $property_value[0] ) ) ? $property_value[0] : $property_value; |
||
92 | $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $property_value . $output['suffix']; |
||
93 | } |
||
96 |
For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this: