| Conditions | 3 |
| Paths | 2 |
| Total Lines | 223 |
| 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 |
||
| 248 | public function form( $instance ) { |
||
| 249 | $instance = wp_parse_args( |
||
| 250 | $instance, |
||
| 251 | array( |
||
| 252 | 'code' => '', |
||
| 253 | 'emailPlaceholder' => '', |
||
| 254 | 'processingLabel' => '', |
||
| 255 | 'successLabel' => '', |
||
| 256 | 'errorLabel' => '', |
||
| 257 | 'interests' => '', |
||
| 258 | 'signupFieldTag' => '', |
||
| 259 | 'signupFieldValue' => '', |
||
| 260 | 'customBackgroundButtonColor' => '', |
||
| 261 | 'customTextButtonColor' => '', |
||
| 262 | 'cssClass' => '', |
||
| 263 | 'popupMode' => '', |
||
| 264 | 'delay' => '', |
||
| 265 | ) |
||
| 266 | ); |
||
| 267 | |||
| 268 | $this->form_sections = array( |
||
| 269 | array( |
||
| 270 | 'title' => __( 'Text Elements', 'jetpack' ), |
||
| 271 | 'fields' => array( |
||
| 272 | array( |
||
| 273 | 'title' => __( 'Email Placeholder', 'jetpack' ), |
||
| 274 | 'id' => 'jetpack-mailchimp-email', |
||
| 275 | 'placeholder' => __( 'Enter your email', 'jetpack' ), |
||
| 276 | 'default' => __( 'Enter your email', 'jetpack' ), |
||
| 277 | 'type' => 'text', |
||
| 278 | 'name' => esc_attr( $this->get_field_name( 'emailPlaceholder' ) ), |
||
| 279 | 'value' => esc_html( $instance['emailPlaceholder'] ), |
||
| 280 | ), |
||
| 281 | ), |
||
| 282 | ), |
||
| 283 | |||
| 284 | array( |
||
| 285 | 'title' => __( 'Notifications', 'jetpack' ), |
||
| 286 | 'fields' => array( |
||
| 287 | array( |
||
| 288 | 'title' => __( 'Processing', 'jetpack' ), |
||
| 289 | 'id' => 'jetpack-mailchimp-processing-label', |
||
| 290 | 'placeholder' => __( 'Processing', 'jetpack' ), |
||
| 291 | 'default' => __( 'Processing', 'jetpack' ), |
||
| 292 | 'type' => 'text', |
||
| 293 | 'name' => esc_attr( $this->get_field_name( 'processingLabel' ) ), |
||
| 294 | 'value' => esc_html( $instance['processingLabel'] ), |
||
| 295 | ), |
||
| 296 | |||
| 297 | array( |
||
| 298 | 'title' => __( 'Success text', 'jetpack' ), |
||
| 299 | 'id' => 'jetpack-mailchimp-success-text', |
||
| 300 | 'placeholder' => __( 'Success! You are on the list.', 'jetpack' ), |
||
| 301 | 'default' => __( 'Success! You are on the list.', 'jetpack' ), |
||
| 302 | 'type' => 'text', |
||
| 303 | 'name' => esc_attr( $this->get_field_name( 'successLabel' ) ), |
||
| 304 | 'value' => esc_html( $instance['successLabel'] ), |
||
| 305 | ), |
||
| 306 | |||
| 307 | array( |
||
| 308 | 'title' => __( 'Error text', 'jetpack' ), |
||
| 309 | 'id' => 'jetpack-mailchimp-error-label', |
||
| 310 | 'placeholder' => __( 'Whoops! There was an error and we could not process your subscription. Please reload the page and try again.', 'jetpack' ), |
||
| 311 | 'default' => __( 'Whoops! There was an error and we could not process your subscription. Please reload the page and try again.', 'jetpack' ), |
||
| 312 | 'type' => 'text', |
||
| 313 | 'name' => esc_attr( $this->get_field_name( 'errorLabel' ) ), |
||
| 314 | 'value' => esc_html( $instance['errorLabel'] ), |
||
| 315 | ), |
||
| 316 | ), |
||
| 317 | ), |
||
| 318 | |||
| 319 | array( |
||
| 320 | 'title' => __( 'Mailchimp Groups', 'jetpack' ), |
||
| 321 | 'fields' => array( |
||
| 322 | array( |
||
| 323 | 'type' => 'groups', |
||
| 324 | ), |
||
| 325 | ), |
||
| 326 | 'extra_content' => array( |
||
| 327 | array( |
||
| 328 | 'text' => __( 'Learn about groups', 'jetpack' ), |
||
| 329 | 'link' => 'https://mailchimp.com/help/send-groups-audience/', |
||
| 330 | 'type' => 'link', |
||
| 331 | ), |
||
| 332 | ), |
||
| 333 | ), |
||
| 334 | |||
| 335 | array( |
||
| 336 | 'title' => __( 'Signup Location Tracking', 'jetpack' ), |
||
| 337 | 'fields' => array( |
||
| 338 | array( |
||
| 339 | 'title' => __( 'Signup Field Tag', 'jetpack' ), |
||
| 340 | 'id' => 'jetpack-mailchimp-signup-tag', |
||
| 341 | 'placeholder' => __( 'SIGNUP', 'jetpack' ), |
||
| 342 | 'default' => '', |
||
| 343 | 'type' => 'text', |
||
| 344 | 'name' => esc_attr( $this->get_field_name( 'signupFieldTag' ) ), |
||
| 345 | 'value' => esc_html( $instance['signupFieldTag'] ), |
||
| 346 | ), |
||
| 347 | |||
| 348 | array( |
||
| 349 | 'title' => __( 'Signup Field Value', 'jetpack' ), |
||
| 350 | 'id' => 'jetpack-mailchimp-signup-value', |
||
| 351 | 'placeholder' => __( 'website', 'jetpack' ), |
||
| 352 | 'default' => '', |
||
| 353 | 'type' => 'text', |
||
| 354 | 'name' => esc_attr( $this->get_field_name( 'signupFieldValue' ) ), |
||
| 355 | 'value' => esc_html( $instance['signupFieldValue'] ), |
||
| 356 | ), |
||
| 357 | ), |
||
| 358 | 'extra_content' => array( |
||
| 359 | array( |
||
| 360 | 'text' => __( 'Learn about signup location tracking(opens in a new tab)', 'jetpack' ), |
||
| 361 | 'link' => 'https://mailchimp.com/help/determine-webpage-signup-location/', |
||
| 362 | 'type' => 'link', |
||
| 363 | ), |
||
| 364 | ), |
||
| 365 | ), |
||
| 366 | |||
| 367 | array( |
||
| 368 | 'title' => __( 'Mailchimp Connection', 'jetpack' ), |
||
| 369 | 'extra_content' => array( |
||
| 370 | array( |
||
| 371 | 'text' => __( 'Manage Connection', 'jetpack' ), |
||
| 372 | 'link' => 'connect_url', |
||
| 373 | 'type' => 'link', |
||
| 374 | ), |
||
| 375 | ), |
||
| 376 | ), |
||
| 377 | |||
| 378 | array( |
||
| 379 | 'title' => __( 'Button Color Settings', 'jetpack' ), |
||
| 380 | 'fields' => array( |
||
| 381 | array( |
||
| 382 | 'id' => 'jetpack-mailchimp-button-color', |
||
| 383 | 'type' => 'color', |
||
| 384 | 'value' => esc_html( $instance['customBackgroundButtonColor'] ), |
||
| 385 | 'default' => '', |
||
| 386 | 'name' => esc_attr( $this->get_field_name( 'customBackgroundButtonColor' ) ), |
||
| 387 | 'label' => __( 'Button Color', 'jetpack' ), |
||
| 388 | ), |
||
| 389 | |||
| 390 | array( |
||
| 391 | 'id' => 'jetpack-mailchimp-button-text-color', |
||
| 392 | 'type' => 'color', |
||
| 393 | 'value' => esc_html( $instance['customTextButtonColor'] ), |
||
| 394 | 'default' => '', |
||
| 395 | 'name' => esc_attr( $this->get_field_name( 'customTextButtonColor' ) ), |
||
| 396 | 'label' => __( 'Button Text Color', 'jetpack' ), |
||
| 397 | ), |
||
| 398 | ), |
||
| 399 | ), |
||
| 400 | |||
| 401 | array( |
||
| 402 | 'title' => __( 'Advanced', 'jetpack' ), |
||
| 403 | 'fields' => array( |
||
| 404 | array( |
||
| 405 | 'title' => __( 'Additional CSS class(es)', 'jetpack' ), |
||
| 406 | 'id' => 'jetpack-mailchimp-css-class', |
||
| 407 | 'placeholder' => '', |
||
| 408 | 'default' => '', |
||
| 409 | 'type' => 'text', |
||
| 410 | 'name' => esc_attr( $this->get_field_name( 'cssClass' ) ), |
||
| 411 | 'value' => esc_html( $instance['cssClass'] ), |
||
| 412 | ), |
||
| 413 | |||
| 414 | array( |
||
| 415 | 'title' => __( 'Activate popup mode', 'jetpack' ), |
||
| 416 | 'type' => 'checkbox', |
||
| 417 | 'name' => esc_attr( $this->get_field_name( 'popupMode' ) ), |
||
| 418 | 'value' => esc_html( $instance['popupMode'] ), |
||
| 419 | ), |
||
| 420 | |||
| 421 | array( |
||
| 422 | 'title' => __( 'Popup delay in miliseconds (only non-AMP)', 'jetpack' ), |
||
| 423 | 'type' => 'number', |
||
| 424 | 'name' => esc_attr( $this->get_field_name( 'delay' ) ), |
||
| 425 | 'value' => esc_html( $instance['delay'] ), |
||
| 426 | 'default' => '0', |
||
| 427 | 'placeholder' => '', |
||
| 428 | ), |
||
| 429 | ), |
||
| 430 | ), |
||
| 431 | ); |
||
| 432 | |||
| 433 | $this->placeholder_data = array( |
||
| 434 | 'instructions' => __( 'You need to connect your Mailchimp account and choose a list in order to start collecting Email subscribers.', 'jetpack' ), |
||
| 435 | 'setupButtonText' => __( 'Set up Mailchimp form', 'jetpack' ), |
||
| 436 | 'recheckText' => __( 'Re-check Connection', 'jetpack' ), |
||
| 437 | ); |
||
| 438 | |||
| 439 | if ( ! empty( $instance['code'] ) ) { |
||
| 440 | ?> |
||
| 441 | <p class="mailchimp-code"> |
||
| 442 | <label for="<?php echo esc_attr( $this->get_field_id( 'code' ) ); ?>"> |
||
| 443 | <?php |
||
| 444 | /* translators: %1$s is replaced mailchimp suppoert link */ |
||
| 445 | echo sprintf( __( 'Code: <a href="%s" target="_blank">( ? )</a>', 'jetpack' ), 'https://en.support.wordpress.com/mailchimp/' ); |
||
| 446 | ?> |
||
| 447 | </label> |
||
| 448 | <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'code' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'code' ) ); ?>" rows="3"><?php echo esc_textarea( $instance['code'] ); ?></textarea> |
||
| 449 | </p> |
||
| 450 | <p class="jetpack-mailchimp-new-form-wrapper"> |
||
| 451 | <input type="checkbox" id="jetpack-mailchimp-new-form" name="<?php echo esc_attr( $this->get_field_name( 'new_form' ) ); ?>" > <?php echo esc_html__( 'Check this if you want to use the new form for this widget (the code in the box above will be deleted)', 'jetpack' ); ?> |
||
| 452 | </p> |
||
| 453 | <?php |
||
| 454 | } |
||
| 455 | |||
| 456 | ?> |
||
| 457 | <div class="mailchimp-widget-jetpack-form-wrapper"></div> |
||
| 458 | <script> |
||
| 459 | |||
| 460 | var mailchimpAdmin = { |
||
| 461 | formData: '<?php echo wp_json_encode( $this->form_sections ); ?>', |
||
| 462 | placeholderData: '<?php echo wp_json_encode( $this->placeholder_data ); ?>', |
||
| 463 | oldForm: <?php echo ! empty( $instance['code'] ) ? 'true' : 'false'; ?>, |
||
| 464 | interests: '<?php echo esc_html( $instance['interests'] ); ?>', |
||
| 465 | interestsFieldName: '<?php echo esc_attr( $this->get_field_name( 'interests' ) ); ?>' |
||
| 466 | } |
||
| 467 | jQuery( window ).trigger( 'jetpack_mailchimp_load_form' ); |
||
| 468 | </script> |
||
| 469 | <?php |
||
| 470 | } |
||
| 471 | |||
| 475 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: