| 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 | * @param array $media  | 
            ||
| 62 | * @return array  | 
            ||
| 63 | */  | 
            ||
| 64 | 	public function create_media_item( $media ) { | 
            ||
| 65 | 		foreach ( $media as & $media_item ) { | 
            ||
| 66 | $title = sanitize_title( basename( $media_item['url'] ) );  | 
            ||
| 67 | $guid = isset( $media['guid'] ) ? $media['guid'] : null;  | 
            ||
| 68 | |||
| 69 | $media_id = videopress_create_new_media_item( $title, $guid );  | 
            ||
| 70 | |||
| 71 | wp_update_attachment_metadata( $media_id, array(  | 
            ||
| 72 | 'original' => array(  | 
            ||
| 73 | 'url' => $media_item['url'],  | 
            ||
| 74 | ),  | 
            ||
| 75 | ) );  | 
            ||
| 76 | |||
| 77 | $media_item['post'] = get_post( $media_id );  | 
            ||
| 78 | }  | 
            ||
| 79 | |||
| 80 | return array( 'media' => $media );  | 
            ||
| 81 | }  | 
            ||
| 82 | |||
| 83 | /**  | 
            ||
| 84 | * @param array $request  | 
            ||
| 85 | *  | 
            ||
| 86 | * @return bool  | 
            ||
| 87 | */  | 
            ||
| 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  | 
            ||
| 174 |