File media.php
has 1498 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* WordPress Administration Media API.
*
* @package WordPress
Function get_media_item
has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring. Open
function get_media_item( $attachment_id, $args = null ) {
global $redir_tab;
if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) )
$thumb_url = $thumb_url[0];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function media_upload_form_handler
has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring. Open
function media_upload_form_handler() {
check_admin_referer('media-form');
$errors = null;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method get_media_item
has 159 lines of code (exceeds 25 allowed). Consider refactoring. Open
function get_media_item( $attachment_id, $args = null ) {
global $redir_tab;
if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) )
$thumb_url = $thumb_url[0];
Function media_upload_library_form
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
function media_upload_library_form($errors) {
global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
media_upload_header();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method media_upload_library_form
has 122 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_upload_library_form($errors) {
global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
media_upload_header();
Method media_upload_gallery_form
has 120 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_upload_gallery_form($errors) {
global $redir_tab, $type;
$redir_tab = 'gallery';
media_upload_header();
Method media_upload_form
has 97 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_upload_form( $errors = null ) {
global $type, $tab;
$flash_action_url = admin_url('async-upload.php');
Method media_upload_type_url_form
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_upload_type_url_form($type = 'file', $errors = null, $id = null) {
media_upload_header();
$post_id = intval($_REQUEST['post_id']);
Method type_url_form_image
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
function type_url_form_image() {
if ( !apply_filters( 'disable_captions', '' ) ) {
$caption = '
<tr>
Function media_upload_audio
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
function media_upload_audio() {
$errors = array();
$id = 0;
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function media_upload_video
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
function media_upload_video() {
$errors = array();
$id = 0;
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function media_upload_image
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
function media_upload_image() {
$errors = array();
$id = 0;
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function media_upload_file
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
function media_upload_file() {
$errors = array();
$id = 0;
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method media_upload_form_handler
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_upload_form_handler() {
check_admin_referer('media-form');
$errors = null;
Method get_attachment_fields_to_edit
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
function get_attachment_fields_to_edit($post, $errors = null) {
if ( is_int($post) )
$post =& get_post($post);
if ( is_array($post) )
$post = (object) $post;
Function get_media_items
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
function get_media_items( $post_id, $errors ) {
if ( $post_id ) {
$post = get_post($post_id);
if ( $post && $post->post_type == 'attachment' )
$attachments = array($post->ID => $post);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method wp_iframe
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
function wp_iframe($content_func /* ... */) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
<head>
Function image_size_input_fields
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
function image_size_input_fields( $post, $check = '' ) {
// get a list of the actual pixel dimensions of each possible intermediate version of this image
$size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size'));
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method media_upload_image
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_upload_image() {
$errors = array();
$id = 0;
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
Method media_upload_type_form
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_upload_type_form($type = 'file', $errors = null, $id = null) {
media_upload_header();
$post_id = intval($_REQUEST['post_id']);
Method media_upload_audio
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_upload_audio() {
$errors = array();
$id = 0;
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
Method media_upload_video
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_upload_video() {
$errors = array();
$id = 0;
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
Method media_upload_file
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_upload_file() {
$errors = array();
$id = 0;
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
Function the_media_upload_tabs
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
function the_media_upload_tabs() {
global $redir_tab;
$tabs = media_upload_tabs();
if ( !empty($tabs) ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method media_handle_upload
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_handle_upload($file_id, $post_id, $post_data = array()) {
$overrides = array('test_form'=>false);
$time = current_time('mysql');
if ( $post = get_post($post_id) ) {
Function get_attachment_fields_to_edit
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function get_attachment_fields_to_edit($post, $errors = null) {
if ( is_int($post) )
$post =& get_post($post);
if ( is_array($post) )
$post = (object) $post;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method image_size_input_fields
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function image_size_input_fields( $post, $check = '' ) {
// get a list of the actual pixel dimensions of each possible intermediate version of this image
$size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size'));
Method media_handle_sideload
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
$overrides = array('test_form'=>false);
$file = wp_handle_sideload($file_array, $overrides);
if ( isset($file['error']) )
Function media_handle_upload
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
function media_handle_upload($file_id, $post_id, $post_data = array()) {
$overrides = array('test_form'=>false);
$time = current_time('mysql');
if ( $post = get_post($post_id) ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method get_image_send_to_editor
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') {
Method image_add_caption
has 8 arguments (exceeds 4 allowed). Consider refactoring. Open
function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
Function media_upload_form
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function media_upload_form( $errors = null ) {
global $type, $tab;
$flash_action_url = admin_url('async-upload.php');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function media_handle_sideload
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
$overrides = array('test_form'=>false);
$file = wp_handle_sideload($file_array, $overrides);
if ( isset($file['error']) )
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
Avoid too many return
statements within this method. Open
return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
Avoid too many return
statements within this method. Open
return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
Avoid too many return
statements within this method. Open
return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
Function media_sideload_image
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function media_sideload_image($file, $post_id, $desc = null) {
if (!empty($file) ) {
// Download file to temp location
$tmp = download_url($file);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Similar blocks of code found in 2 locations. Consider refactoring. Open
function media_upload_audio() {
$errors = array();
$id = 0;
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 435.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
function media_upload_video() {
$errors = array();
$id = 0;
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 435.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76