Conditions | 13 |
Paths | 1536 |
Total Lines | 118 |
Code Lines | 70 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
92 | function display_setup_form( $error = null ) { |
||
93 | global $wpdb; |
||
94 | |||
95 | $sql = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->users ) ); |
||
96 | $user_table = ( $wpdb->get_var( $sql ) != null ); |
||
97 | |||
98 | // Ensure that Blogs appear in search engines by default. |
||
99 | $blog_public = 1; |
||
100 | if ( isset( $_POST['weblog_title'] ) ) { |
||
101 | $blog_public = isset( $_POST['blog_public'] ); |
||
102 | } |
||
103 | |||
104 | $weblog_title = isset( $_POST['weblog_title'] ) ? trim( wp_unslash( $_POST['weblog_title'] ) ) : ''; |
||
105 | $user_name = isset($_POST['user_name']) ? trim( wp_unslash( $_POST['user_name'] ) ) : ''; |
||
106 | $admin_email = isset( $_POST['admin_email'] ) ? trim( wp_unslash( $_POST['admin_email'] ) ) : ''; |
||
107 | |||
108 | if ( ! is_null( $error ) ) { |
||
109 | ?> |
||
110 | <h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1> |
||
111 | <p class="message"><?php echo $error; ?></p> |
||
112 | <?php } ?> |
||
113 | <form id="setup" method="post" action="install.php?step=2" novalidate="novalidate"> |
||
114 | <table class="form-table"> |
||
115 | <tr> |
||
116 | <th scope="row"><label for="weblog_title"><?php _e( 'Site Title' ); ?></label></th> |
||
117 | <td><input name="weblog_title" type="text" id="weblog_title" size="25" value="<?php echo esc_attr( $weblog_title ); ?>" /></td> |
||
118 | </tr> |
||
119 | <tr> |
||
120 | <th scope="row"><label for="user_login"><?php _e('Username'); ?></label></th> |
||
121 | <td> |
||
122 | <?php |
||
123 | if ( $user_table ) { |
||
124 | _e('User(s) already exists.'); |
||
125 | echo '<input name="user_name" type="hidden" value="admin" />'; |
||
126 | } else { |
||
127 | ?><input name="user_name" type="text" id="user_login" size="25" value="<?php echo esc_attr( sanitize_user( $user_name, true ) ); ?>" /> |
||
128 | <p><?php _e( 'Usernames can have only alphanumeric characters, spaces, underscores, hyphens, periods, and the @ symbol.' ); ?></p> |
||
129 | <?php |
||
130 | } ?> |
||
131 | </td> |
||
132 | </tr> |
||
133 | <?php if ( ! $user_table ) : ?> |
||
134 | <tr class="form-field form-required user-pass1-wrap"> |
||
135 | <th scope="row"> |
||
136 | <label for="pass1"> |
||
137 | <?php _e( 'Password' ); ?> |
||
138 | </label> |
||
139 | </th> |
||
140 | <td> |
||
141 | <div class=""> |
||
142 | <?php $initial_password = isset( $_POST['admin_password'] ) ? stripslashes( $_POST['admin_password'] ) : wp_generate_password( 18 ); ?> |
||
143 | <input type="password" name="admin_password" id="pass1" class="regular-text" autocomplete="off" data-reveal="1" data-pw="<?php echo esc_attr( $initial_password ); ?>" aria-describedby="pass-strength-result" /> |
||
144 | <button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-start-masked="<?php echo (int) isset( $_POST['admin_password'] ); ?>" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>"> |
||
145 | <span class="dashicons dashicons-hidden"></span> |
||
146 | <span class="text"><?php _e( 'Hide' ); ?></span> |
||
147 | </button> |
||
148 | <div id="pass-strength-result" aria-live="polite"></div> |
||
149 | </div> |
||
150 | <p><span class="description important hide-if-no-js"> |
||
151 | <strong><?php _e( 'Important:' ); ?></strong> |
||
152 | <?php /* translators: The non-breaking space prevents 1Password from thinking the text "log in" should trigger a password save prompt. */ ?> |
||
153 | <?php _e( 'You will need this password to log in. Please store it in a secure location.' ); ?></span></p> |
||
154 | </td> |
||
155 | </tr> |
||
156 | <tr class="form-field form-required user-pass2-wrap hide-if-js"> |
||
157 | <th scope="row"> |
||
158 | <label for="pass2"><?php _e( 'Repeat Password' ); ?> |
||
159 | <span class="description"><?php _e( '(required)' ); ?></span> |
||
160 | </label> |
||
161 | </th> |
||
162 | <td> |
||
163 | <input name="admin_password2" type="password" id="pass2" autocomplete="off" /> |
||
164 | </td> |
||
165 | </tr> |
||
166 | <tr class="pw-weak"> |
||
167 | <th scope="row"><?php _e( 'Confirm Password' ); ?></th> |
||
168 | <td> |
||
169 | <label> |
||
170 | <input type="checkbox" name="pw_weak" class="pw-checkbox" /> |
||
171 | <?php _e( 'Confirm use of weak password' ); ?> |
||
172 | </label> |
||
173 | </td> |
||
174 | </tr> |
||
175 | <?php endif; ?> |
||
176 | <tr> |
||
177 | <th scope="row"><label for="admin_email"><?php _e( 'Your Email' ); ?></label></th> |
||
178 | <td><input name="admin_email" type="email" id="admin_email" size="25" value="<?php echo esc_attr( $admin_email ); ?>" /> |
||
179 | <p><?php _e( 'Double-check your email address before continuing.' ); ?></p></td> |
||
180 | </tr> |
||
181 | <tr> |
||
182 | <th scope="row"><?php has_action( 'blog_privacy_selector' ) ? _e( 'Site Visibility' ) : _e( 'Search Engine Visibility' ); ?></th> |
||
183 | <td> |
||
184 | <fieldset> |
||
185 | <legend class="screen-reader-text"><span><?php has_action( 'blog_privacy_selector' ) ? _e( 'Site Visibility' ) : _e( 'Search Engine Visibility' ); ?> </span></legend> |
||
186 | <?php |
||
187 | if ( has_action( 'blog_privacy_selector' ) ) { ?> |
||
188 | <input id="blog-public" type="radio" name="blog_public" value="1" <?php checked( 1, $blog_public ); ?> /> |
||
189 | <label for="blog-public"><?php _e( 'Allow search engines to index this site' );?></label><br/> |
||
190 | <input id="blog-norobots" type="radio" name="blog_public" value="0" <?php checked( 0, $blog_public ); ?> /> |
||
191 | <label for="blog-norobots"><?php _e( 'Discourage search engines from indexing this site' ); ?></label> |
||
192 | <p class="description"><?php _e( 'Note: Neither of these options blocks access to your site — it is up to search engines to honor your request.' ); ?></p> |
||
193 | <?php |
||
194 | /** This action is documented in wp-admin/options-reading.php */ |
||
195 | do_action( 'blog_privacy_selector' ); |
||
196 | } else { ?> |
||
197 | <label for="blog_public"><input name="blog_public" type="checkbox" id="blog_public" value="0" <?php checked( 0, $blog_public ); ?> /> |
||
198 | <?php _e( 'Discourage search engines from indexing this site' ); ?></label> |
||
199 | <p class="description"><?php _e( 'It is up to search engines to honor this request.' ); ?></p> |
||
200 | <?php } ?> |
||
201 | </fieldset> |
||
202 | </td> |
||
203 | </tr> |
||
204 | </table> |
||
205 | <p class="step"><?php submit_button( __( 'Install WordPress' ), 'large', 'Submit', false, array( 'id' => 'submit' ) ); ?></p> |
||
206 | <input type="hidden" name="language" value="<?php echo isset( $_REQUEST['language'] ) ? esc_attr( $_REQUEST['language'] ) : ''; ?>" /> |
||
207 | </form> |
||
208 | <?php |
||
209 | } // end display_setup_form() |
||
210 | |||
412 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.