Conditions | 7 |
Paths | 4 |
Total Lines | 75 |
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 |
||
71 | '.wp-block-jetpack-calendly .button{%1$s%2$s}', |
||
72 | ! empty( $submit_button_text_color ) |
||
73 | ? 'color:#' . sanitize_hex_color_no_hash( $submit_button_text_color ) . ';' |
||
74 | : '', |
||
75 | ! empty( $submit_button_background_color ) |
||
76 | ? 'background-color:#' . sanitize_hex_color_no_hash( $submit_button_background_color ) . ';' |
||
77 | : '' |
||
78 | ); |
||
79 | wp_add_inline_style( 'jetpack-calendly-external-css', $inline_styles ); |
||
80 | } |
||
81 | |||
82 | $content = sprintf( |
||
83 | '<div class="%1$s"><a class="button" href="" onclick="Calendly.initPopupWidget({url:\'%2$s\'});return false;">%3$s</a></div>', |
||
84 | esc_attr( $classes ), |
||
85 | esc_url( $url ), |
||
86 | wp_kses_post( $submit_button_text ) |
||
87 | ); |
||
88 | } else { // Button style. |
||
89 | $content = sprintf( |
||
90 | '<div class="calendly-inline-widget %1$s" data-url="%2$s" style="min-width:320px;height:630px;"></div>', |
||
91 | esc_attr( $classes ), |
||
92 | esc_url( $url ) |
||
93 | ); |
||
94 | } |
||
95 | |||
96 | return $content; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Get filtered attributes. |
||
101 | * |
||
102 | * @param array $attributes Array containing the Calendly block attributes. |
||
103 | * @param string $attribute_name String containing the attribute name to get. |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | function jetpack_calendly_block_get_attribute( $attributes, $attribute_name ) { |
||
108 | if ( isset( $attributes[ $attribute_name ] ) ) { |
||
109 | return $attributes[ $attribute_name ]; |
||
110 | } |
||
111 | |||
112 | $default_attributes = array( |
||
113 | 'style' => 'inline', |
||
114 | 'submitButtonText' => esc_html__( 'Schedule time with me', 'jetpack' ), |
||
115 | 'backgroundColor' => 'ffffff', |
||
116 | 'textColor' => '4D5055', |
||
117 | 'primaryColor' => '00A2FF', |
||
118 | 'hideEventTypeDetails' => false, |
||
119 | ); |
||
120 | |||
121 | if ( isset( $default_attributes[ $attribute_name ] ) ) { |
||
122 | return $default_attributes[ $attribute_name ]; |
||
123 | } |
||
124 | } |
||
125 |