| Conditions | 10 |
| Paths | 6 |
| Total Lines | 37 |
| Code Lines | 30 |
| 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 |
||
| 98 | public function add_customer_meta_fields( $user ) { |
||
| 99 | |||
| 100 | if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
||
| 101 | return; |
||
| 102 | } |
||
| 103 | |||
| 104 | $show_fields = $this->get_customer_meta_fields(); |
||
| 105 | |||
| 106 | foreach ( $show_fields as $fieldset_key => $fieldset ) : |
||
| 107 | ?> |
||
| 108 | <h2><?php echo $fieldset['title']; ?></h2> |
||
| 109 | <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
||
| 110 | <?php foreach ( $fieldset['fields'] as $key => $field ) : ?> |
||
| 111 | <tr> |
||
| 112 | <th> |
||
| 113 | <label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ); ?></label> |
||
| 114 | </th> |
||
| 115 | <td> |
||
| 116 | <?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?> |
||
| 117 | <select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?> wpi_select2" style="width: 25em;"> |
||
| 118 | <?php |
||
| 119 | $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
||
|
|
|||
| 120 | foreach ( $field['options'] as $option_key => $option_value ) : |
||
| 121 | ?> |
||
| 122 | <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option> |
||
| 123 | <?php endforeach; ?> |
||
| 124 | </select> |
||
| 125 | <?php elseif ( ! empty( $field['type'] ) && 'checkbox' === $field['type'] ) : ?> |
||
| 126 | <input type="checkbox" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="1" class="<?php echo esc_attr( $field['class'] ); ?>" <?php checked( (int) get_user_meta( $user->ID, $key, true ), 1, true ); ?> /> |
||
| 127 | <?php else : ?> |
||
| 128 | <input type="text" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $this->get_user_meta( $user->ID, $key ) ); ?>" class="<?php echo ( ! empty( $field['class'] ) ? esc_attr( $field['class'] ) : 'regular-text' ); ?>" /> |
||
| 129 | <?php endif; ?> |
||
| 130 | <p class="description"><?php echo wp_kses_post( $field['description'] ); ?></p> |
||
| 131 | </td> |
||
| 132 | </tr> |
||
| 133 | <?php endforeach; ?> |
||
| 134 | </table> |
||
| 135 | <?php |
||
| 185 | return new GetPaid_Admin_Profile(); |