Conditions | 3 |
Paths | 4 |
Total Lines | 61 |
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 |
||
75 | public function parse_shortcode( $attrs ) { |
||
76 | // We allow for overriding the presentation labels. |
||
77 | $data = shortcode_atts( |
||
78 | array( |
||
79 | 'blog_id' => $this->get_blog_id(), |
||
80 | 'title' => __( 'Join my email list', 'jetpack' ), |
||
81 | 'email_placeholder' => __( 'Enter your email', 'jetpack' ), |
||
82 | 'submit_label' => __( 'Join My Email List', 'jetpack' ), |
||
83 | 'consent_text' => __( 'By clicking submit, you agree to share your email address with the site owner and MailChimp to receive marketing, updates, and other emails from the site owner. Use the unsubscribe link in those emails to opt out at any time.', 'jetpack' ), |
||
84 | 'processing_label' => __( 'Processing...', 'jetpack' ), |
||
85 | 'success_label' => __( 'Success! You\'ve been added to the list.', 'jetpack' ), |
||
86 | 'error_label' => __( "Oh no! Unfortunately there was an error.\nPlease try reloading this page and adding your email once more.", 'jetpack' ), |
||
87 | 'classname' => self::$css_classname_prefix, |
||
88 | 'dom_id' => uniqid( self::$css_classname_prefix . '_', false ), |
||
89 | ), |
||
90 | $attrs |
||
91 | ); |
||
92 | |||
93 | if ( ! wp_script_is( 'jetpack-email-subscribe', 'enqueued' ) ) { |
||
94 | wp_enqueue_script( 'jetpack-email-subscribe' ); |
||
95 | } |
||
96 | |||
97 | if ( ! wp_style_is( 'jetpack-email-subscribe', 'enqueue' ) ) { |
||
98 | wp_enqueue_style( 'jetpack-email-subscribe' ); |
||
99 | } |
||
100 | |||
101 | wp_add_inline_script( |
||
102 | 'jetpack-email-subscribe', |
||
103 | sprintf( |
||
104 | "try{JetpackEmailSubscribe.activate( '%s', '%s', '%s' );}catch(e){}", |
||
105 | esc_js( $data['blog_id'] ), |
||
106 | esc_js( $data['dom_id'] ), |
||
107 | esc_js( $data['classname'] ) |
||
108 | ) |
||
109 | ); |
||
110 | |||
111 | return sprintf( |
||
112 | '<div class="%1$s" id="%2$s"> |
||
113 | <h2>%3$s</h2> |
||
114 | <form> |
||
115 | <input type="email" class="%1$s-email" required placeholder="%4$s"> |
||
116 | <button type="submit" class="%1$s-submit">%6$s</button> |
||
117 | <label class="%1$s-consent-label"> |
||
118 | <small>%5$s</small> |
||
119 | </label> |
||
120 | </form> |
||
121 | <div class="%1$s-processing">%7$s</div> |
||
122 | <div class="%1$s-success">%8$s</div> |
||
123 | <div class="%1$s-error">%9$s</div> |
||
124 | </div>', |
||
125 | esc_attr( $data['classname'] ), |
||
126 | esc_attr( $data['dom_id'] ), |
||
127 | esc_html( $data['title'] ), |
||
128 | esc_html( $data['email_placeholder'] ), |
||
129 | esc_html( $data['consent_text'] ), |
||
130 | esc_html( $data['submit_label'] ), |
||
131 | nl2br( esc_html( $data['processing_label'] ) ), |
||
132 | nl2br( esc_html( $data['success_label'] ) ), |
||
133 | nl2br( esc_html( $data['error_label'] ) ) |
||
134 | ); |
||
135 | } |
||
136 | |||
140 |