Conditions | 12 |
Paths | 578 |
Total Lines | 78 |
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 |
||
114 | public function prepare_items() { |
||
115 | $columns = $this->get_columns(); |
||
116 | $hidden = array(); |
||
117 | $data = array(); |
||
118 | $sortable = false; |
||
119 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
||
120 | |||
121 | $per_page = 25; |
||
122 | |||
123 | $crons = ppp_get_shceduled_crons(); |
||
124 | |||
125 | $cron_tally = array(); |
||
126 | foreach ( $crons as $key => $cron ) { |
||
127 | $ppp_data = $cron; |
||
128 | $timestamp = $ppp_data['timestamp']; |
||
129 | |||
130 | $cron_tally[$timestamp] = isset( $cron_tally[$timestamp] ) ? $cron_tally[$timestamp] + 1 : 1; |
||
131 | |||
132 | $name_parts = explode( '_', $ppp_data['args'][1] ); |
||
133 | $post_id = $ppp_data['args'][0]; |
||
134 | $index = $name_parts[1]; |
||
135 | $service = isset( $name_parts[3] ) ? $name_parts[3] : 'tw'; |
||
136 | $builder = 'ppp_' . $service . '_build_share_message'; |
||
137 | $post_meta = apply_filters( 'ppp_get_scheduled_items_' . $service, array(), $post_id ); |
||
138 | $image_url = ''; |
||
139 | |||
140 | if ( ! empty( $post_meta[$index]['attachment_id'] ) ) { |
||
141 | $image_url = ppp_post_has_media( $post_id, $service, true, $post_meta[ $index ]['attachment_id'] ); |
||
142 | } elseif ( ! empty( $post_meta[ $index ]['image'] ) ) { |
||
143 | $image_url = $post_meta[ $index ]['image']; |
||
144 | } |
||
145 | |||
146 | $conflict = $cron_tally[ $timestamp ] > 1 ? true : false; |
||
147 | |||
148 | $data[ $key ] = array( |
||
149 | 'post_id' => $post_id, |
||
150 | 'post_title' => get_the_title( $post_id ), |
||
151 | 'service' => $service, |
||
152 | 'index' => $index, |
||
153 | 'date' => $timestamp + ( get_option( 'gmt_offset' ) * 3600 ), |
||
154 | 'content' => function_exists( $builder ) ? $builder( $post_id, $ppp_data['args'][1], false ) : '', |
||
155 | 'name' => 'sharedate_' . $index . '_' . $post_id, |
||
156 | 'conflict' => $conflict, |
||
157 | ); |
||
158 | |||
159 | if ( ! empty( $image_url ) ) { |
||
160 | $data[ $key ]['image_url'] = $image_url; |
||
161 | } |
||
162 | |||
163 | $description_function = 'ppp_' . $service . '_get_share_description'; |
||
164 | if ( function_exists( $description_function ) ) { |
||
165 | $description = $description_function( $post_id, $index ); |
||
166 | if ( ! empty( $description ) ) { |
||
167 | $data[ $key ]['content'] .= '<br />' . $description; |
||
168 | } |
||
169 | } |
||
170 | |||
171 | } |
||
172 | |||
173 | $total_items = count( $data ); |
||
174 | |||
175 | $offset = isset( $_GET['paged'] ) ? $_GET['paged'] : 1; |
||
176 | |||
177 | $data = array_slice( $data, ( $offset - 1 ) * $per_page, $per_page, true ); |
||
178 | $this->items = $data; |
||
179 | |||
180 | |||
181 | $this->set_pagination_args( array( |
||
182 | 'total_items' => $total_items, |
||
183 | 'per_page' => $per_page, |
||
184 | 'total_pages' => ceil( $total_items / $per_page ), |
||
185 | ) ); |
||
186 | |||
187 | $this->items = $data; |
||
188 | |||
189 | return $this->items; |
||
190 | |||
191 | } |
||
192 | } |
||
195 |