Conditions | 8 |
Paths | 13 |
Total Lines | 56 |
Code Lines | 30 |
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 |
||
88 | public function update_videopress_media_item( $request ) { |
||
89 | |||
90 | $id = $request['post_id']; |
||
91 | $status = $request['status']; |
||
92 | $format = $request['format']; |
||
93 | $info = $request['info']; |
||
94 | |||
95 | if ( ! $attachment = get_post( $id ) ) { |
||
96 | return false; |
||
97 | } |
||
98 | |||
99 | $attachment->guid = $info['original']; |
||
100 | |||
101 | wp_update_post( $attachment ); |
||
102 | |||
103 | // Update the vp guid and set it to a direct meta property. |
||
104 | update_post_meta( $id, 'videopress_guid', $info['guid'] ); |
||
105 | |||
106 | $meta = wp_get_attachment_metadata( $id ); |
||
107 | |||
108 | $meta['width'] = $info['width']; |
||
109 | $meta['height'] = $info['height']; |
||
110 | $meta['original']['url'] = $info['original']; |
||
111 | $meta['videopress'] = $info; |
||
112 | $meta['videopress']['url'] = 'https://videopress.com/v/' . $info['guid']; |
||
113 | |||
114 | // Update file statuses |
||
115 | $valid_formats = array( 'hd', 'ogg', 'mp4', 'dvd' ); |
||
116 | if ( in_array( $format, $valid_formats ) ) { |
||
117 | $meta['file_statuses'][ $format ] = $status; |
||
118 | } |
||
119 | |||
120 | if ( ! get_post_meta( $id, '_thumbnail_id', true ) ) { |
||
121 | // Update the poster in the VideoPress info. |
||
122 | $thumbnail_id = videopress_download_poster_image( $info['poster'], $id ); |
||
123 | |||
124 | if ( is_int( $thumbnail_id ) ) { |
||
125 | update_post_meta( $id, '_thumbnail_id', $thumbnail_id ); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | wp_update_attachment_metadata( $id, $meta ); |
||
130 | |||
131 | videopress_update_meta_data( $id ); |
||
132 | |||
133 | // update the meta to tell us that we're processing or complete |
||
134 | update_post_meta( $id, 'videopress_status', videopress_is_finished_processing( $id ) ? 'complete' : 'processing' ); |
||
135 | |||
136 | // Get the attached file and if there isn't one, then let's update it with the one from the server. |
||
137 | $file = get_attached_file( $id ); |
||
138 | if ( ! $file && is_string( $info['original'] ) ) { |
||
139 | videopress_download_video( $info['original'], $id ); |
||
140 | } |
||
141 | |||
142 | return true; |
||
143 | } |
||
144 | |||
174 |