Conditions | 8 |
Paths | 8 |
Total Lines | 53 |
Code Lines | 31 |
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 |
||
61 | public function update_videopress_info( $vp_info ) { |
||
62 | $errors = null; |
||
63 | foreach ( $vp_info as $vp_item ) { |
||
64 | $id = $vp_item['post_id']; |
||
65 | $guid = $vp_item['guid']; |
||
66 | |||
67 | $attachment = get_post( $id ); |
||
68 | |||
69 | if ( ! $attachment ) { |
||
70 | $errors[] = array( |
||
71 | 'id' => $id, |
||
72 | 'error' => 'Post not found', |
||
73 | ); |
||
74 | |||
75 | continue; |
||
76 | } |
||
77 | |||
78 | $attachment->guid = $vp_item['original']; |
||
79 | $attachment->file = $vp_item['original']; |
||
80 | |||
81 | wp_update_post( $attachment ); |
||
82 | |||
83 | // Update the vp guid and set it to a direct meta property. |
||
84 | update_post_meta( $id, 'videopress_guid', $guid ); |
||
85 | |||
86 | $meta = wp_get_attachment_metadata( $attachment->ID ); |
||
87 | |||
88 | $current_poster = get_post_meta( $id, '_thumbnail_id' ); |
||
89 | |||
90 | $meta['width'] = $vp_item['width']; |
||
91 | $meta['height'] = $vp_item['height']; |
||
92 | $meta['original']['url'] = $vp_item['original']; |
||
93 | $meta['videopress'] = $vp_item; |
||
94 | $meta['videopress']['url'] = 'https://videopress.com/v/' . $guid; |
||
95 | |||
96 | if ( ! $current_poster && isset( $vp_item['poster'] ) && ! empty( $vp_item['poster'] ) ) { |
||
97 | $thumbnail_id = videopress_download_poster_image( $vp_item['poster'], $id ); |
||
98 | update_post_meta( $id, '_thumbnail_id', $thumbnail_id ); |
||
99 | } |
||
100 | |||
101 | wp_update_attachment_metadata( $attachment->ID, $meta ); |
||
102 | |||
103 | // update the meta to tell us that we're processing or complete |
||
104 | update_post_meta( $id, 'videopress_status', videopress_is_finished_processing( $attachment->ID ) ? 'complete' : 'processing' ); |
||
105 | } |
||
106 | |||
107 | if ( count( $errors ) > 0 ) { |
||
108 | return array( 'errors' => $errors ); |
||
109 | |||
110 | } else { |
||
111 | return true; |
||
112 | } |
||
113 | } |
||
114 | |||
150 |