Conditions | 23 |
Paths | 271 |
Total Lines | 93 |
Code Lines | 70 |
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 |
||
93 | public function single_row( $item, $style = '' ) { |
||
94 | // Set up the hover actions for this user |
||
95 | $actions = array(); |
||
96 | $view_link = '?page=formidable-entries&frm_action=show&id=' . $item->id; |
||
97 | |||
98 | $this->get_actions( $actions, $item, $view_link ); |
||
99 | |||
100 | $action_links = $this->row_actions( $actions ); |
||
101 | |||
102 | // Set up the checkbox ( because the user is editable, otherwise its empty ) |
||
103 | $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />"; |
||
104 | |||
105 | $r = "<tr id='item-action-{$item->id}'$style>"; |
||
106 | |||
107 | list( $columns, $hidden, , $primary ) = $this->get_column_info(); |
||
108 | $action_col = false; |
||
109 | |||
110 | foreach ( $columns as $column_name => $column_display_name ) { |
||
111 | $class = $column_name . ' column-' . $column_name; |
||
112 | |||
113 | if ( $column_name === $primary ) { |
||
114 | $class .= ' column-primary'; |
||
115 | } |
||
116 | |||
117 | if ( in_array( $column_name, $hidden ) ) { |
||
118 | $class .= ' frm_hidden'; |
||
119 | } else if ( ! $action_col && ! in_array( $column_name, array( 'cb', 'id', 'form_id', 'post_id' ) ) ) { |
||
120 | $action_col = $column_name; |
||
121 | } |
||
122 | |||
123 | $attributes = 'class="' . esc_attr( $class ) . '"'; |
||
124 | unset($class); |
||
125 | $attributes .= ' data-colname="' . $column_display_name . '"'; |
||
126 | |||
127 | $col_name = preg_replace( '/^(' . $this->params['form'] . '_)/', '', $column_name ); |
||
128 | $this->column_name = $col_name; |
||
129 | |||
130 | switch ( $col_name ) { |
||
131 | case 'cb': |
||
132 | $r .= "<th scope='row' class='check-column'>$checkbox</th>"; |
||
133 | break; |
||
134 | case 'ip': |
||
135 | case 'id': |
||
136 | case 'item_key': |
||
137 | $val = $item->{$col_name}; |
||
138 | break; |
||
139 | case 'name': |
||
140 | case 'description': |
||
141 | $val = FrmAppHelper::truncate(strip_tags($item->{$col_name}), 100); |
||
142 | break; |
||
143 | case 'created_at': |
||
144 | case 'updated_at': |
||
145 | $date = FrmAppHelper::get_formatted_time($item->{$col_name}); |
||
146 | $val = '<abbr title="' . esc_attr( FrmAppHelper::get_formatted_time( $item->{$col_name}, '', 'g:i:s A' ) ) . '">' . $date . '</abbr>'; |
||
147 | break; |
||
148 | case 'is_draft': |
||
149 | $val = empty($item->is_draft) ? __( 'No') : __( 'Yes'); |
||
150 | break; |
||
151 | case 'form_id': |
||
152 | $val = FrmFormsHelper::edit_form_link($item->form_id); |
||
153 | break; |
||
154 | case 'post_id': |
||
155 | $val = FrmAppHelper::post_edit_link($item->post_id); |
||
156 | break; |
||
157 | case 'user_id': |
||
158 | $user = get_userdata($item->user_id); |
||
159 | $val = $user->user_login; |
||
160 | break; |
||
161 | default: |
||
162 | $val = apply_filters( 'frm_entries_' . $col_name . '_column', false, compact( 'item' ) ); |
||
163 | if ( $val === false ) { |
||
164 | $this->get_column_value( $item, $val ); |
||
165 | } |
||
166 | break; |
||
167 | } |
||
168 | |||
169 | if ( isset( $val ) ) { |
||
170 | $r .= "<td $attributes>"; |
||
171 | if ( $column_name == $action_col ) { |
||
172 | $edit_link = '?page=formidable-entries&frm_action=edit&id=' . $item->id; |
||
173 | $r .= '<a href="' . esc_url( isset( $actions['edit'] ) ? $edit_link : $view_link ) . '" class="row-title" >' . $val . '</a> '; |
||
174 | $r .= $action_links; |
||
175 | } else { |
||
176 | $r .= $val; |
||
177 | } |
||
178 | $r .= '</td>'; |
||
179 | } |
||
180 | unset($val); |
||
181 | } |
||
182 | $r .= '</tr>'; |
||
183 | |||
184 | return $r; |
||
185 | } |
||
186 | |||
238 |