Conditions | 12 |
Paths | 12 |
Total Lines | 47 |
Code Lines | 37 |
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 |
||
102 | public function add_customer_meta_fields( $user ) { |
||
103 | if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
||
104 | return; |
||
105 | } |
||
106 | |||
107 | $show_fields = $this->get_customer_meta_fields(); |
||
108 | |||
109 | $customer = getpaid_get_customer_by_user_id( (int) $user->ID ); |
||
110 | |||
111 | foreach ( $show_fields as $fieldset_key => $fieldset ) : |
||
112 | ?> |
||
113 | <h2><?php echo esc_html( $fieldset['title'] ); ?></h2> |
||
114 | <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
||
115 | <?php foreach ( $fieldset['fields'] as $key => $field ) : |
||
116 | if ( ! empty( $customer ) ) { |
||
117 | if ( strpos( $key, '_wpinv_' ) === 0 ) { |
||
118 | $save_key = substr( $key , 7 ); |
||
119 | } else { |
||
120 | $save_key = $key; |
||
121 | } |
||
122 | |||
123 | $value = $customer->get( $save_key ); |
||
124 | } else { |
||
125 | $value = $this->get_user_meta( $user->ID, $key ); |
||
126 | } |
||
127 | ?> |
||
128 | <tr> |
||
129 | <th> |
||
130 | <label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ); ?></label> |
||
131 | </th> |
||
132 | <td> |
||
133 | <?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?> |
||
134 | <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;"> |
||
135 | <?php foreach ( $field['options'] as $option_key => $option_value ) : ?> |
||
136 | <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $value, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option> |
||
137 | <?php endforeach; ?> |
||
138 | </select> |
||
139 | <?php elseif ( ! empty( $field['type'] ) && 'checkbox' === $field['type'] ) : ?> |
||
140 | <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) $value, 1, true ); ?> /> |
||
141 | <?php else : ?> |
||
142 | <input type="text" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $value ); ?>" class="<?php echo ( ! empty( $field['class'] ) ? esc_attr( $field['class'] ) : 'regular-text' ); ?>" /> |
||
143 | <?php endif; ?> |
||
144 | <p class="description"><?php echo wp_kses_post( $field['description'] ); ?></p> |
||
145 | </td> |
||
146 | </tr> |
||
147 | <?php endforeach; ?> |
||
148 | </table> |
||
149 | <?php |
||
223 |