WordPress/WordPress

View on GitHub
wp-admin/includes/media.php

Summary

Maintainability
F
3 wks
Test Coverage

File media.php has 2347 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * WordPress Administration Media API.
 *
 * @package WordPress
Severity: Major
Found in wp-admin/includes/media.php - About 6 days to fix

    Function get_media_item has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
    Open

    function get_media_item( $attachment_id, $args = null ) {
        global $redir_tab;
    
        $thumb_url     = false;
        $attachment_id = (int) $attachment_id;
    Severity: Minor
    Found in wp-admin/includes/media.php - About 1 day to fix

    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 get_compat_media_markup has a Cognitive Complexity of 68 (exceeds 5 allowed). Consider refactoring.
    Open

    function get_compat_media_markup( $attachment_id, $args = null ) {
        $post = get_post( $attachment_id );
    
        $default_args = array(
            'errors'   => null,
    Severity: Minor
    Found in wp-admin/includes/media.php - About 1 day to fix

    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 56 (exceeds 5 allowed). Consider refactoring.
    Open

    function media_upload_form_handler() {
        check_admin_referer( 'media-form' );
    
        $errors = null;
    
    
    Severity: Minor
    Found in wp-admin/includes/media.php - About 1 day to fix

    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 208 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function get_media_item( $attachment_id, $args = null ) {
        global $redir_tab;
    
        $thumb_url     = false;
        $attachment_id = (int) $attachment_id;
    Severity: Major
    Found in wp-admin/includes/media.php - About 1 day to fix

      Function media_handle_upload has a Cognitive Complexity of 48 (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' );
          $post = get_post( $post_id );
      
          if ( $post ) {
      Severity: Minor
      Found in wp-admin/includes/media.php - About 7 hrs to fix

      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 attachment_submitbox_metadata has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
      Open

      function attachment_submitbox_metadata() {
          $post          = get_post();
          $attachment_id = $post->ID;
      
          $file     = get_attached_file( $attachment_id );
      Severity: Minor
      Found in wp-admin/includes/media.php - About 6 hrs to fix

      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 159 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();
      
      
      Severity: Major
      Found in wp-admin/includes/media.php - About 6 hrs to fix

        Method attachment_submitbox_metadata has 157 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function attachment_submitbox_metadata() {
            $post          = get_post();
            $attachment_id = $post->ID;
        
            $file     = get_attached_file( $attachment_id );
        Severity: Major
        Found in wp-admin/includes/media.php - About 6 hrs to fix

          Function wp_media_upload_handler has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
          Open

          function wp_media_upload_handler() {
              $errors = array();
              $id     = 0;
          
              if ( isset( $_POST['html-upload'] ) && ! empty( $_FILES ) ) {
          Severity: Minor
          Found in wp-admin/includes/media.php - About 6 hrs to fix

          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_compat_media_markup has 136 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function get_compat_media_markup( $attachment_id, $args = null ) {
              $post = get_post( $attachment_id );
          
              $default_args = array(
                  'errors'   => null,
          Severity: Major
          Found in wp-admin/includes/media.php - About 5 hrs to fix

            Method media_upload_gallery_form has 133 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();
            Severity: Major
            Found in wp-admin/includes/media.php - About 5 hrs to fix

              Function media_upload_library_form has a Cognitive Complexity of 34 (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();
              
              
              Severity: Minor
              Found in wp-admin/includes/media.php - About 5 hrs to fix

              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 has 124 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function media_upload_form( $errors = null ) {
                  global $type, $tab;
              
                  if ( ! _device_can_upload() ) {
                      echo '<p>' . sprintf(
              Severity: Major
              Found in wp-admin/includes/media.php - About 4 hrs to fix

                Method edit_form_image_editor has 122 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function edit_form_image_editor( $post ) {
                    $open = isset( $_GET['image-editor'] );
                
                    if ( $open ) {
                        require_once ABSPATH . 'wp-admin/includes/image-edit.php';
                Severity: Major
                Found in wp-admin/includes/media.php - About 4 hrs to fix

                  Method media_handle_upload has 98 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' );
                      $post = get_post( $post_id );
                  
                      if ( $post ) {
                  Severity: Major
                  Found in wp-admin/includes/media.php - About 3 hrs to fix

                    Method media_upload_type_url_form has 96 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function media_upload_type_url_form( $type = null, $errors = null, $id = null ) {
                        if ( null === $type ) {
                            $type = 'image';
                        }
                    
                    
                    Severity: Major
                    Found in wp-admin/includes/media.php - About 3 hrs to fix

                      Method get_attachment_fields_to_edit has 87 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 );
                          }
                      
                      
                      Severity: Major
                      Found in wp-admin/includes/media.php - About 3 hrs to fix

                        Method wp_media_insert_url_form has 85 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        function wp_media_insert_url_form( $default_view = 'image' ) {
                            /** This filter is documented in wp-admin/includes/media.php */
                            if ( ! apply_filters( 'disable_captions', '' ) ) {
                                $caption = '
                                <tr class="image-only">
                        Severity: Major
                        Found in wp-admin/includes/media.php - About 3 hrs to fix

                          Function edit_form_image_editor has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function edit_form_image_editor( $post ) {
                              $open = isset( $_GET['image-editor'] );
                          
                              if ( $open ) {
                                  require_once ABSPATH . 'wp-admin/includes/image-edit.php';
                          Severity: Minor
                          Found in wp-admin/includes/media.php - About 3 hrs to fix

                          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 wp_add_id3_tag_data has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function wp_add_id3_tag_data( &$metadata, $data ) {
                              foreach ( array( 'id3v2', 'id3v1' ) as $version ) {
                                  if ( ! empty( $data[ $version ]['comments'] ) ) {
                                      foreach ( $data[ $version ]['comments'] as $key => $list ) {
                                          if ( 'length' !== $key && ! empty( $list ) ) {
                          Severity: Minor
                          Found in wp-admin/includes/media.php - About 3 hrs to fix

                          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 75 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          function media_upload_form_handler() {
                              check_admin_referer( 'media-form' );
                          
                              $errors = null;
                          
                          
                          Severity: Major
                          Found in wp-admin/includes/media.php - About 3 hrs to fix

                            Function wp_read_video_metadata has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                            Open

                            function wp_read_video_metadata( $file ) {
                                if ( ! file_exists( $file ) ) {
                                    return false;
                                }
                            
                            
                            Severity: Minor
                            Found in wp-admin/includes/media.php - About 2 hrs to fix

                            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_media_upload_handler has 68 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            function wp_media_upload_handler() {
                                $errors = array();
                                $id     = 0;
                            
                                if ( isset( $_POST['html-upload'] ) && ! empty( $_FILES ) ) {
                            Severity: Major
                            Found in wp-admin/includes/media.php - About 2 hrs to fix

                              Method wp_read_video_metadata has 65 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              function wp_read_video_metadata( $file ) {
                                  if ( ! file_exists( $file ) ) {
                                      return false;
                                  }
                              
                              
                              Severity: Major
                              Found in wp-admin/includes/media.php - About 2 hrs to fix

                                Function get_attachment_fields_to_edit has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                                Open

                                function get_attachment_fields_to_edit( $post, $errors = null ) {
                                    if ( is_int( $post ) ) {
                                        $post = get_post( $post );
                                    }
                                
                                
                                Severity: Minor
                                Found in wp-admin/includes/media.php - About 2 hrs to fix

                                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 wp_media_attach_action has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                                Open

                                function wp_media_attach_action( $parent_id, $action = 'attach' ) {
                                    global $wpdb;
                                
                                    if ( ! $parent_id ) {
                                        return;
                                Severity: Minor
                                Found in wp-admin/includes/media.php - About 2 hrs to fix

                                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 get_media_items has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                                Open

                                function get_media_items( $post_id, $errors ) {
                                    $attachments = array();
                                
                                    if ( $post_id ) {
                                        $post = get_post( $post_id );
                                Severity: Minor
                                Found in wp-admin/includes/media.php - About 2 hrs to fix

                                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_sideload has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                function media_handle_sideload( $file_array, $post_id = 0, $desc = null, $post_data = array() ) {
                                    $overrides = array( 'test_form' => false );
                                
                                    if ( isset( $post_data['post_date'] ) && substr( $post_data['post_date'], 0, 4 ) > 0 ) {
                                        $time = $post_data['post_date'];
                                Severity: Minor
                                Found in wp-admin/includes/media.php - About 1 hr to fix

                                  Method wp_iframe has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  function wp_iframe( $content_func, ...$args ) {
                                      global $body_id;
                                  
                                      _wp_admin_html_begin();
                                      ?>
                                  Severity: Minor
                                  Found in wp-admin/includes/media.php - About 1 hr to fix

                                    Function media_handle_sideload has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                    function media_handle_sideload( $file_array, $post_id = 0, $desc = null, $post_data = array() ) {
                                        $overrides = array( 'test_form' => false );
                                    
                                        if ( isset( $post_data['post_date'] ) && substr( $post_data['post_date'], 0, 4 ) > 0 ) {
                                            $time = $post_data['post_date'];
                                    Severity: Minor
                                    Found in wp-admin/includes/media.php - About 1 hr to fix

                                    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_type_form has 42 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 = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
                                    Severity: Minor
                                    Found in wp-admin/includes/media.php - About 1 hr to fix

                                      Method image_size_input_fields has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                      function image_size_input_fields( $post, $check = '' ) {
                                          /**
                                           * Filters the names and labels of the default image sizes.
                                           *
                                           * @since 3.3.0
                                      Severity: Minor
                                      Found in wp-admin/includes/media.php - About 1 hr to fix

                                        Method wp_read_audio_metadata has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                                        Open

                                        function wp_read_audio_metadata( $file ) {
                                            if ( ! file_exists( $file ) ) {
                                                return false;
                                            }
                                        
                                        
                                        Severity: Minor
                                        Found in wp-admin/includes/media.php - About 1 hr to fix

                                          Method wp_media_attach_action has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                                          Open

                                          function wp_media_attach_action( $parent_id, $action = 'attach' ) {
                                              global $wpdb;
                                          
                                              if ( ! $parent_id ) {
                                                  return;
                                          Severity: Minor
                                          Found in wp-admin/includes/media.php - About 1 hr to fix

                                            Function image_size_input_fields has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                            function image_size_input_fields( $post, $check = '' ) {
                                                /**
                                                 * Filters the names and labels of the default image sizes.
                                                 *
                                                 * @since 3.3.0
                                            Severity: Minor
                                            Found in wp-admin/includes/media.php - About 1 hr to fix

                                            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_sideload_image has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                            function media_sideload_image( $file, $post_id = 0, $desc = null, $return_type = 'html' ) {
                                                if ( ! empty( $file ) ) {
                                            
                                                    $allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif', 'webp' );
                                            
                                            
                                            Severity: Minor
                                            Found in wp-admin/includes/media.php - About 1 hr to fix

                                            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 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();
                                                $default = 'type';
                                            
                                            
                                            Severity: Minor
                                            Found in wp-admin/includes/media.php - About 1 hr to fix

                                            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 wp_read_audio_metadata has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                            function wp_read_audio_metadata( $file ) {
                                                if ( ! file_exists( $file ) ) {
                                                    return false;
                                                }
                                            
                                            
                                            Severity: Minor
                                            Found in wp-admin/includes/media.php - About 1 hr to fix

                                            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_sideload_image has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                                            Open

                                            function media_sideload_image( $file, $post_id = 0, $desc = null, $return_type = 'html' ) {
                                                if ( ! empty( $file ) ) {
                                            
                                                    $allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif', 'webp' );
                                            
                                            
                                            Severity: Minor
                                            Found in wp-admin/includes/media.php - About 1 hr to fix

                                              Method get_media_items has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                                              Open

                                              function get_media_items( $post_id, $errors ) {
                                                  $attachments = array();
                                              
                                                  if ( $post_id ) {
                                                      $post = get_post( $post_id );
                                              Severity: Minor
                                              Found in wp-admin/includes/media.php - About 1 hr to fix

                                                Method wp_add_id3_tag_data has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                                                Open

                                                function wp_add_id3_tag_data( &$metadata, $data ) {
                                                    foreach ( array( 'id3v2', 'id3v1' ) as $version ) {
                                                        if ( ! empty( $data[ $version ]['comments'] ) ) {
                                                            foreach ( $data[ $version ]['comments'] as $key => $list ) {
                                                                if ( 'length' !== $key && ! empty( $list ) ) {
                                                Severity: Minor
                                                Found in wp-admin/includes/media.php - About 1 hr to fix

                                                  Function media_upload_form has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                                  Open

                                                  function media_upload_form( $errors = null ) {
                                                      global $type, $tab;
                                                  
                                                      if ( ! _device_can_upload() ) {
                                                          echo '<p>' . sprintf(
                                                  Severity: Minor
                                                  Found in wp-admin/includes/media.php - About 1 hr to fix

                                                  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 the_media_upload_tabs has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                                                  Open

                                                  function the_media_upload_tabs() {
                                                      global $redir_tab;
                                                      $tabs    = media_upload_tabs();
                                                      $default = 'type';
                                                  
                                                  
                                                  Severity: Minor
                                                  Found in wp-admin/includes/media.php - About 1 hr to fix

                                                    Method wp_get_media_creation_timestamp has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                                    Open

                                                    function wp_get_media_creation_timestamp( $metadata ) {
                                                        $creation_date = false;
                                                    
                                                        if ( empty( $metadata['fileformat'] ) ) {
                                                            return $creation_date;
                                                    Severity: Minor
                                                    Found in wp-admin/includes/media.php - About 1 hr to fix

                                                      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 = '' ) {
                                                      Severity: Major
                                                      Found in wp-admin/includes/media.php - About 1 hr to fix

                                                        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 = '' ) {
                                                        Severity: Major
                                                        Found in wp-admin/includes/media.php - About 1 hr to fix

                                                          Function wp_get_media_creation_timestamp has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                                          Open

                                                          function wp_get_media_creation_timestamp( $metadata ) {
                                                              $creation_date = false;
                                                          
                                                              if ( empty( $metadata['fileformat'] ) ) {
                                                                  return $creation_date;
                                                          Severity: Minor
                                                          Found in wp-admin/includes/media.php - About 55 mins to fix

                                                          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', 'image', $errors, $id );
                                                          Severity: Major
                                                          Found in wp-admin/includes/media.php - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                        return $src;
                                                            Severity: Major
                                                            Found in wp-admin/includes/media.php - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                      return $html;
                                                              Severity: Major
                                                              Found in wp-admin/includes/media.php - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                        return new WP_Error( 'image_sideload_failed' );
                                                                Severity: Major
                                                                Found in wp-admin/includes/media.php - About 30 mins to fix

                                                                  Function wp_iframe has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                  Open

                                                                  function wp_iframe( $content_func, ...$args ) {
                                                                      global $body_id;
                                                                  
                                                                      _wp_admin_html_begin();
                                                                      ?>
                                                                  Severity: Minor
                                                                  Found in wp-admin/includes/media.php - About 25 mins to fix

                                                                  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 get_image_send_to_editor has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                  Open

                                                                  function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = false, $size = 'medium', $alt = '' ) {
                                                                  
                                                                      $html = get_image_tag( $id, $alt, '', $align, $size );
                                                                  
                                                                      if ( $rel ) {
                                                                  Severity: Minor
                                                                  Found in wp-admin/includes/media.php - About 25 mins to fix

                                                                  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 3 locations. Consider refactoring.
                                                                  Open

                                                                              if ( isset( $attachment['image_alt'] ) ) {
                                                                                  $image_alt = wp_unslash( $attachment['image_alt'] );
                                                                  
                                                                                  if ( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) !== $image_alt ) {
                                                                                      $image_alt = wp_strip_all_tags( $image_alt, true );
                                                                  Severity: Major
                                                                  Found in wp-admin/includes/media.php and 2 other locations - About 50 mins to fix
                                                                  wp-admin/includes/ajax-actions.php on lines 3148..3154
                                                                  wp-admin/includes/post.php on lines 421..430

                                                                  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 97.

                                                                  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

                                                                  Further Reading

                                                                  There are no issues that match your filters.

                                                                  Category
                                                                  Status