WordPress/WordPress

View on GitHub
wp-includes/media.php

Summary

Maintainability
F
1 mo
Test Coverage

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

<?php
/**
 * WordPress API for media display.
 *
 * @package WordPress
Severity: Major
Found in wp-includes/media.php - About 1 wk to fix

    Function get_post_galleries has a Cognitive Complexity of 90 (exceeds 5 allowed). Consider refactoring.
    Open

    function get_post_galleries( $post, $html = true ) {
        $post = get_post( $post );
    
        if ( ! $post ) {
            return array();
    Severity: Minor
    Found in wp-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 wp_enqueue_media has 239 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function wp_enqueue_media( $args = array() ) {
        // Enqueue me just once per page, please.
        if ( did_action( 'wp_enqueue_media' ) ) {
            return;
        }
    Severity: Major
    Found in wp-includes/media.php - About 1 day to fix

      Function wp_prepare_attachment_for_js has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
      Open

      function wp_prepare_attachment_for_js( $attachment ) {
          $attachment = get_post( $attachment );
      
          if ( ! $attachment ) {
              return;
      Severity: Minor
      Found in wp-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 wp_video_shortcode has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
      Open

      function wp_video_shortcode( $attr, $content = '' ) {
          global $content_width;
          $post_id = get_post() ? get_the_ID() : 0;
      
          static $instance = 0;
      Severity: Minor
      Found in wp-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 wp_prepare_attachment_for_js has 182 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function wp_prepare_attachment_for_js( $attachment ) {
          $attachment = get_post( $attachment );
      
          if ( ! $attachment ) {
              return;
      Severity: Major
      Found in wp-includes/media.php - About 7 hrs to fix

        Function wp_playlist_shortcode has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
        Open

        function wp_playlist_shortcode( $attr ) {
            global $content_width;
            $post = get_post();
        
            static $instance = 0;
        Severity: Minor
        Found in wp-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

        Method gallery_shortcode has 180 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function gallery_shortcode( $attr ) {
            $post = get_post();
        
            static $instance = 0;
            ++$instance;
        Severity: Major
        Found in wp-includes/media.php - About 7 hrs to fix

          Method wp_playlist_shortcode has 173 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function wp_playlist_shortcode( $attr ) {
              global $content_width;
              $post = get_post();
          
              static $instance = 0;
          Severity: Major
          Found in wp-includes/media.php - About 6 hrs to fix

            Function gallery_shortcode has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
            Open

            function gallery_shortcode( $attr ) {
                $post = get_post();
            
                static $instance = 0;
                ++$instance;
            Severity: Minor
            Found in wp-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 wp_video_shortcode has 154 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function wp_video_shortcode( $attr, $content = '' ) {
                global $content_width;
                $post_id = get_post() ? get_the_ID() : 0;
            
                static $instance = 0;
            Severity: Major
            Found in wp-includes/media.php - About 6 hrs to fix

              Function wp_get_loading_optimization_attributes has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
              Open

              function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
                  global $wp_query;
              
                  /**
                   * Filters whether to short-circuit loading optimization attributes.
              Severity: Minor
              Found in wp-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

              Function image_get_intermediate_size has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
              Open

              function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
                  $imagedata = wp_get_attachment_metadata( $post_id );
              
                  if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
                      return false;
              Severity: Minor
              Found in wp-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

              Function image_resize_dimensions has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
              Open

              function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
              
                  if ( $orig_w <= 0 || $orig_h <= 0 ) {
                      return false;
                  }
              Severity: Minor
              Found in wp-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

              Function wp_filter_content_tags has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
              Open

              function wp_filter_content_tags( $content, $context = null ) {
                  if ( null === $context ) {
                      $context = current_filter();
                  }
              
              
              Severity: Minor
              Found in wp-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

              Function wp_audio_shortcode has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
              Open

              function wp_audio_shortcode( $attr, $content = '' ) {
                  $post_id = get_post() ? get_the_ID() : 0;
              
                  static $instance = 0;
                  ++$instance;
              Severity: Minor
              Found in wp-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

              Function wp_calculate_image_srcset has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
              Open

              function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id = 0 ) {
                  /**
                   * Pre-filters the image meta to be able to fix inconsistencies in the stored data.
                   *
                   * @since 4.5.0
              Severity: Minor
              Found in wp-includes/media.php - About 4 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_get_attachment_image has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
              Open

              function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) {
                  $html  = '';
                  $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
              
                  if ( $image ) {
              Severity: Minor
              Found in wp-includes/media.php - About 4 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_image_file_matches_image_meta has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
              Open

              function wp_image_file_matches_image_meta( $image_location, $image_meta, $attachment_id = 0 ) {
                  $match = false;
              
                  // Ensure the $image_meta is valid.
                  if ( isset( $image_meta['file'] ) && strlen( $image_meta['file'] ) > 4 ) {
              Severity: Minor
              Found in wp-includes/media.php - About 4 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_post_galleries has 100 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function get_post_galleries( $post, $html = true ) {
                  $post = get_post( $post );
              
                  if ( ! $post ) {
                      return array();
              Severity: Major
              Found in wp-includes/media.php - About 4 hrs to fix

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

                function wp_audio_shortcode( $attr, $content = '' ) {
                    $post_id = get_post() ? get_the_ID() : 0;
                
                    static $instance = 0;
                    ++$instance;
                Severity: Major
                Found in wp-includes/media.php - About 3 hrs to fix

                  Function wp_enqueue_media has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function wp_enqueue_media( $args = array() ) {
                      // Enqueue me just once per page, please.
                      if ( did_action( 'wp_enqueue_media' ) ) {
                          return;
                      }
                  Severity: Minor
                  Found in wp-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 wp_get_loading_optimization_attributes has 92 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
                      global $wp_query;
                  
                      /**
                       * Filters whether to short-circuit loading optimization attributes.
                  Severity: Major
                  Found in wp-includes/media.php - About 3 hrs to fix

                    Method img_caption_shortcode has 81 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function img_caption_shortcode( $attr, $content = '' ) {
                        // New-style shortcode with the caption inside the shortcode with the link and image tags.
                        if ( ! isset( $attr['caption'] ) ) {
                            if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
                                $content         = $matches[1];
                    Severity: Major
                    Found in wp-includes/media.php - About 3 hrs to fix

                      Method wp_calculate_image_srcset has 77 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id = 0 ) {
                          /**
                           * Pre-filters the image meta to be able to fix inconsistencies in the stored data.
                           *
                           * @since 4.5.0
                      Severity: Major
                      Found in wp-includes/media.php - About 3 hrs to fix

                        Function wp_img_tag_add_loading_optimization_attrs has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function wp_img_tag_add_loading_optimization_attrs( $image, $context ) {
                            $width             = preg_match( '/ width=["\']([0-9]+)["\']/', $image, $match_width ) ? (int) $match_width[1] : null;
                            $height            = preg_match( '/ height=["\']([0-9]+)["\']/', $image, $match_height ) ? (int) $match_height[1] : null;
                            $loading_val       = preg_match( '/ loading=["\']([A-Za-z]+)["\']/', $image, $match_loading ) ? $match_loading[1] : null;
                            $fetchpriority_val = preg_match( '/ fetchpriority=["\']([A-Za-z]+)["\']/', $image, $match_fetchpriority ) ? $match_fetchpriority[1] : null;
                        Severity: Minor
                        Found in wp-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_img_tag_add_loading_optimization_attrs has 69 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        function wp_img_tag_add_loading_optimization_attrs( $image, $context ) {
                            $width             = preg_match( '/ width=["\']([0-9]+)["\']/', $image, $match_width ) ? (int) $match_width[1] : null;
                            $height            = preg_match( '/ height=["\']([0-9]+)["\']/', $image, $match_height ) ? (int) $match_height[1] : null;
                            $loading_val       = preg_match( '/ loading=["\']([A-Za-z]+)["\']/', $image, $match_loading ) ? $match_loading[1] : null;
                            $fetchpriority_val = preg_match( '/ fetchpriority=["\']([A-Za-z]+)["\']/', $image, $match_fetchpriority ) ? $match_fetchpriority[1] : null;
                        Severity: Major
                        Found in wp-includes/media.php - About 2 hrs to fix

                          Method image_resize_dimensions has 68 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
                          
                              if ( $orig_w <= 0 || $orig_h <= 0 ) {
                                  return false;
                              }
                          Severity: Major
                          Found in wp-includes/media.php - About 2 hrs to fix

                            Function get_attachment_taxonomies has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                            Open

                            function get_attachment_taxonomies( $attachment, $output = 'names' ) {
                                if ( is_int( $attachment ) ) {
                                    $attachment = get_post( $attachment );
                                } elseif ( is_array( $attachment ) ) {
                                    $attachment = (object) $attachment;
                            Severity: Minor
                            Found in wp-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 image_constrain_size_for_editor has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                            Open

                            function image_constrain_size_for_editor( $width, $height, $size = 'medium', $context = null ) {
                                global $content_width;
                            
                                $_wp_additional_image_sizes = wp_get_additional_image_sizes();
                            
                            
                            Severity: Minor
                            Found in wp-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_filter_content_tags has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            function wp_filter_content_tags( $content, $context = null ) {
                                if ( null === $context ) {
                                    $context = current_filter();
                                }
                            
                            
                            Severity: Major
                            Found in wp-includes/media.php - About 2 hrs to fix

                              Method wp_get_attachment_image has 58 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) {
                                  $html  = '';
                                  $image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
                              
                                  if ( $image ) {
                              Severity: Major
                              Found in wp-includes/media.php - About 2 hrs to fix

                                Method wp_getimagesize has 58 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                function wp_getimagesize( $filename, ?array &$image_info = null ) {
                                    // Don't silence errors when in debug mode, unless running unit tests.
                                    if ( defined( 'WP_DEBUG' ) && WP_DEBUG
                                        && ! defined( 'WP_RUN_CORE_TESTS' )
                                    ) {
                                Severity: Major
                                Found in wp-includes/media.php - About 2 hrs to fix

                                  Function wp_get_registered_image_subsizes has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  function wp_get_registered_image_subsizes() {
                                      $additional_sizes = wp_get_additional_image_sizes();
                                      $all_sizes        = array();
                                  
                                      foreach ( get_intermediate_image_sizes() as $size_name ) {
                                  Severity: Minor
                                  Found in wp-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_getimagesize has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  function wp_getimagesize( $filename, ?array &$image_info = null ) {
                                      // Don't silence errors when in debug mode, unless running unit tests.
                                      if ( defined( 'WP_DEBUG' ) && WP_DEBUG
                                          && ! defined( 'WP_RUN_CORE_TESTS' )
                                      ) {
                                  Severity: Minor
                                  Found in wp-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_plupload_default_settings has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  function wp_plupload_default_settings() {
                                      $wp_scripts = wp_scripts();
                                  
                                      $data = $wp_scripts->get_data( 'wp-plupload', 'data' );
                                      if ( $data && str_contains( $data, '_wpPluploadSettings' ) ) {
                                  Severity: Major
                                  Found in wp-includes/media.php - About 2 hrs to fix

                                    Method image_get_intermediate_size has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                    function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
                                        $imagedata = wp_get_attachment_metadata( $post_id );
                                    
                                        if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
                                            return false;
                                    Severity: Minor
                                    Found in wp-includes/media.php - About 2 hrs to fix

                                      Method image_downsize has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                      function image_downsize( $id, $size = 'medium' ) {
                                          $is_image = wp_attachment_is_image( $id );
                                      
                                          /**
                                           * Filters whether to preempt the output of image_downsize().
                                      Severity: Minor
                                      Found in wp-includes/media.php - About 1 hr to fix

                                        Function image_downsize has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                        function image_downsize( $id, $size = 'medium' ) {
                                            $is_image = wp_attachment_is_image( $id );
                                        
                                            /**
                                             * Filters whether to preempt the output of image_downsize().
                                        Severity: Minor
                                        Found in wp-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 wp_media_personal_data_exporter has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                                        Open

                                        function wp_media_personal_data_exporter( $email_address, $page = 1 ) {
                                            // Limit us to 50 attachments at a time to avoid timing out.
                                            $number = 50;
                                            $page   = (int) $page;
                                        
                                        
                                        Severity: Minor
                                        Found in wp-includes/media.php - About 1 hr to fix

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

                                          function wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ) {
                                              // Ensure the image meta exists.
                                              if ( empty( $image_meta['sizes'] ) ) {
                                                  return $image;
                                              }
                                          Severity: Minor
                                          Found in wp-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 img_caption_shortcode has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                                          Open

                                          function img_caption_shortcode( $attr, $content = '' ) {
                                              // New-style shortcode with the caption inside the shortcode with the link and image tags.
                                              if ( ! isset( $attr['caption'] ) ) {
                                                  if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
                                                      $content         = $matches[1];
                                          Severity: Minor
                                          Found in wp-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_get_attachment_image_src has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                                          Open

                                          function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
                                              // Get a thumbnail or intermediate image if there is one.
                                              $image = image_downsize( $attachment_id, $size );
                                              if ( ! $image ) {
                                                  $src = false;
                                          Severity: Minor
                                          Found in wp-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 attachment_url_to_postid has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                                          Open

                                          function attachment_url_to_postid( $url ) {
                                              global $wpdb;
                                          
                                              $dir  = wp_get_upload_dir();
                                              $path = $url;
                                          Severity: Minor
                                          Found in wp-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_image_editor_choose has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                                          Open

                                          function _wp_image_editor_choose( $args = array() ) {
                                              require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
                                              require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
                                              require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
                                              require_once ABSPATH . WPINC . '/class-avif-info.php';
                                          Severity: Minor
                                          Found in wp-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 wp_underscore_playlist_templates has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                                          Open

                                          function wp_underscore_playlist_templates() {
                                              ?>
                                          <script type="text/html" id="tmpl-wp-playlist-current-item">
                                              <# if ( data.thumb && data.thumb.src ) { #>
                                                  <img src="{{ data.thumb.src }}" alt="" />
                                          Severity: Minor
                                          Found in wp-includes/media.php - About 1 hr to fix

                                            Method image_constrain_size_for_editor has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                                            Open

                                            function image_constrain_size_for_editor( $width, $height, $size = 'medium', $context = null ) {
                                                global $content_width;
                                            
                                                $_wp_additional_image_sizes = wp_get_additional_image_sizes();
                                            
                                            
                                            Severity: Minor
                                            Found in wp-includes/media.php - About 1 hr to fix

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

                                              function get_taxonomies_for_attachments( $output = 'names' ) {
                                                  $taxonomies = array();
                                              
                                                  foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) {
                                                      foreach ( $taxonomy->object_type as $object_type ) {
                                              Severity: Minor
                                              Found in wp-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 wp_image_add_srcset_and_sizes has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                                              Open

                                              function wp_image_add_srcset_and_sizes( $image, $image_meta, $attachment_id ) {
                                                  // Ensure the image meta exists.
                                                  if ( empty( $image_meta['sizes'] ) ) {
                                                      return $image;
                                                  }
                                              Severity: Minor
                                              Found in wp-includes/media.php - About 1 hr to fix

                                                Method get_attachment_taxonomies has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                                                Open

                                                function get_attachment_taxonomies( $attachment, $output = 'names' ) {
                                                    if ( is_int( $attachment ) ) {
                                                        $attachment = get_post( $attachment );
                                                    } elseif ( is_array( $attachment ) ) {
                                                        $attachment = (object) $attachment;
                                                Severity: Minor
                                                Found in wp-includes/media.php - About 1 hr to fix

                                                  Method wp_get_webp_info has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                                                  Open

                                                  function wp_get_webp_info( $filename ) {
                                                      $width  = false;
                                                      $height = false;
                                                      $type   = false;
                                                  
                                                  
                                                  Severity: Minor
                                                  Found in wp-includes/media.php - About 1 hr to fix

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

                                                    function _wp_image_editor_choose( $args = array() ) {
                                                        require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
                                                        require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
                                                        require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
                                                        require_once ABSPATH . WPINC . '/class-avif-info.php';
                                                    Severity: Minor
                                                    Found in wp-includes/media.php - About 1 hr to fix

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

                                                      function wp_get_registered_image_subsizes() {
                                                          $additional_sizes = wp_get_additional_image_sizes();
                                                          $all_sizes        = array();
                                                      
                                                          foreach ( get_intermediate_image_sizes() as $size_name ) {
                                                      Severity: Minor
                                                      Found in wp-includes/media.php - About 1 hr to fix

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

                                                        function wp_calculate_image_sizes( $size, $image_src = null, $image_meta = null, $attachment_id = 0 ) {
                                                            $width = 0;
                                                        
                                                            if ( is_array( $size ) ) {
                                                                $width = absint( $size[0] );
                                                        Severity: Minor
                                                        Found in wp-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 wp_constrain_dimensions has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                                                        Open

                                                        function wp_constrain_dimensions( $current_width, $current_height, $max_width = 0, $max_height = 0 ) {
                                                            if ( ! $max_width && ! $max_height ) {
                                                                return array( $current_width, $current_height );
                                                            }
                                                        
                                                        
                                                        Severity: Minor
                                                        Found in wp-includes/media.php - About 1 hr to fix

                                                          Method get_adjacent_image_link has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                                          Open

                                                          function get_adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) {
                                                              $post        = get_post();
                                                              $attachments = array_values(
                                                                  get_children(
                                                                      array(
                                                          Severity: Minor
                                                          Found in wp-includes/media.php - About 1 hr to fix

                                                            Method attachment_url_to_postid has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                                                            Open

                                                            function attachment_url_to_postid( $url ) {
                                                                global $wpdb;
                                                            
                                                                $dir  = wp_get_upload_dir();
                                                                $path = $url;
                                                            Severity: Minor
                                                            Found in wp-includes/media.php - About 1 hr to fix

                                                              Method wp_image_file_matches_image_meta has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                                              Open

                                                              function wp_image_file_matches_image_meta( $image_location, $image_meta, $attachment_id = 0 ) {
                                                                  $match = false;
                                                              
                                                                  // Ensure the $image_meta is valid.
                                                                  if ( isset( $image_meta['file'] ) && strlen( $image_meta['file'] ) > 4 ) {
                                                              Severity: Minor
                                                              Found in wp-includes/media.php - About 1 hr to fix

                                                                Function wp_get_image_editor has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                                                Open

                                                                function wp_get_image_editor( $path, $args = array() ) {
                                                                    $args['path'] = $path;
                                                                
                                                                    // If the mime type is not set in args, try to extract and set it from the file.
                                                                    if ( ! isset( $args['mime_type'] ) ) {
                                                                Severity: Minor
                                                                Found in wp-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_constrain_dimensions has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                                                Open

                                                                function wp_constrain_dimensions( $current_width, $current_height, $max_width = 0, $max_height = 0 ) {
                                                                    if ( ! $max_width && ! $max_height ) {
                                                                        return array( $current_width, $current_height );
                                                                    }
                                                                
                                                                
                                                                Severity: Minor
                                                                Found in wp-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_image_src_get_dimensions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                                                Open

                                                                function wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id = 0 ) {
                                                                    $dimensions = false;
                                                                
                                                                    // Is it a full size image?
                                                                    if (
                                                                Severity: Minor
                                                                Found in wp-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

                                                                Function wp_img_tag_add_width_and_height_attr has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                                                Open

                                                                function wp_img_tag_add_width_and_height_attr( $image, $context, $attachment_id ) {
                                                                    $image_src         = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';
                                                                    list( $image_src ) = explode( '?', $image_src );
                                                                
                                                                    // Return early if we couldn't get the image source.
                                                                Severity: Minor
                                                                Found in wp-includes/media.php - About 45 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 wp_maybe_add_fetchpriority_high_attr has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                                                Open

                                                                function wp_maybe_add_fetchpriority_high_attr( $loading_attrs, $tag_name, $attr ) {
                                                                    // For now, adding `fetchpriority="high"` is only supported for images.
                                                                    if ( 'img' !== $tag_name ) {
                                                                        return $loading_attrs;
                                                                    }
                                                                Severity: Minor
                                                                Found in wp-includes/media.php - About 45 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 deeply nested control flow statements.
                                                                Open

                                                                                    if ( empty( $attr['sizes'] ) ) {
                                                                                        $attr['sizes'] = $sizes;
                                                                                    }
                                                                Severity: Major
                                                                Found in wp-includes/media.php - About 45 mins to fix

                                                                  Consider simplifying this complex logical expression.
                                                                  Open

                                                                      if (
                                                                          'the_content' !== $context && doing_filter( 'the_content' ) ||
                                                                          'widget_text_content' !== $context && doing_filter( 'widget_text_content' ) ||
                                                                          'widget_block_content' !== $context && doing_filter( 'widget_block_content' )
                                                                      ) {
                                                                  Severity: Major
                                                                  Found in wp-includes/media.php - About 40 mins to fix

                                                                    Consider simplifying this complex logical expression.
                                                                    Open

                                                                            if ( isset( $header_enforced_contexts[ $context ] ) ) {
                                                                                $maybe_in_viewport    = true;
                                                                                $maybe_increase_count = true;
                                                                            } elseif ( ! is_admin() && in_the_loop() && is_main_query() ) {
                                                                                /*
                                                                    Severity: Major
                                                                    Found in wp-includes/media.php - About 40 mins to fix

                                                                      Method image_resize_dimensions has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                      Open

                                                                      function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
                                                                      Severity: Minor
                                                                      Found in wp-includes/media.php - About 35 mins to fix

                                                                        Method get_image_tag has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                        Open

                                                                        function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) {
                                                                        Severity: Minor
                                                                        Found in wp-includes/media.php - About 35 mins to fix

                                                                          Function image_make_intermediate_size has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                                          Open

                                                                          function image_make_intermediate_size( $file, $width, $height, $crop = false ) {
                                                                              if ( $width || $height ) {
                                                                                  $editor = wp_get_image_editor( $file );
                                                                          
                                                                                  if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) {
                                                                          Severity: Minor
                                                                          Found in wp-includes/media.php - About 35 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 wp_plupload_default_settings has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                                          Open

                                                                          function wp_plupload_default_settings() {
                                                                              $wp_scripts = wp_scripts();
                                                                          
                                                                              $data = $wp_scripts->get_data( 'wp-plupload', 'data' );
                                                                              if ( $data && str_contains( $data, '_wpPluploadSettings' ) ) {
                                                                          Severity: Minor
                                                                          Found in wp-includes/media.php - About 35 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 wp_get_webp_info has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                                          Open

                                                                          function wp_get_webp_info( $filename ) {
                                                                              $width  = false;
                                                                              $height = false;
                                                                              $type   = false;
                                                                          
                                                                          
                                                                          Severity: Minor
                                                                          Found in wp-includes/media.php - About 35 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_adjacent_image_link has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                                                          Open

                                                                          function get_adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) {
                                                                              $post        = get_post();
                                                                              $attachments = array_values(
                                                                                  get_children(
                                                                                      array(
                                                                          Severity: Minor
                                                                          Found in wp-includes/media.php - About 35 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 false;
                                                                          Severity: Major
                                                                          Found in wp-includes/media.php - About 30 mins to fix

                                                                            Avoid too many return statements within this method.
                                                                            Open

                                                                                return rtrim( $srcset, ', ' );
                                                                            Severity: Major
                                                                            Found in wp-includes/media.php - About 30 mins to fix

                                                                              Avoid too many return statements within this method.
                                                                              Open

                                                                                  return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
                                                                              Severity: Major
                                                                              Found in wp-includes/media.php - About 30 mins to fix

                                                                                Avoid too many return statements within this method.
                                                                                Open

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

                                                                                  Avoid too many return statements within this method.
                                                                                  Open

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

                                                                                    Avoid too many return statements within this method.
                                                                                    Open

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

                                                                                      Avoid too many return statements within this method.
                                                                                      Open

                                                                                              return preg_replace( '/<img ([^>]+?)[\/ ]*>/', '<img $1' . $attr . ' />', $image );
                                                                                      Severity: Major
                                                                                      Found in wp-includes/media.php - About 30 mins to fix

                                                                                        Avoid too many return statements within this method.
                                                                                        Open

                                                                                            return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context );
                                                                                        Severity: Major
                                                                                        Found in wp-includes/media.php - About 30 mins to fix

                                                                                          Avoid too many return statements within this method.
                                                                                          Open

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

                                                                                            Avoid too many return statements within this method.
                                                                                            Open

                                                                                                return apply_filters( 'wp_audio_shortcode', $html, $atts, $audio, $post_id, $library );
                                                                                            Severity: Major
                                                                                            Found in wp-includes/media.php - About 30 mins to fix

                                                                                              Avoid too many return statements within this method.
                                                                                              Open

                                                                                                      return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context );
                                                                                              Severity: Major
                                                                                              Found in wp-includes/media.php - About 30 mins to fix

                                                                                                Avoid too many return statements within this method.
                                                                                                Open

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

                                                                                                  Avoid too many return statements within this method.
                                                                                                  Open

                                                                                                      return apply_filters( 'wp_video_shortcode', $output, $atts, $video, $post_id, $library );
                                                                                                  Severity: Major
                                                                                                  Found in wp-includes/media.php - About 30 mins to fix

                                                                                                    Avoid too many return statements within this method.
                                                                                                    Open

                                                                                                        return ob_get_clean();
                                                                                                    Severity: Major
                                                                                                    Found in wp-includes/media.php - About 30 mins to fix

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

                                                                                                      function get_media_embedded_in_content( $content, $types = null ) {
                                                                                                          $html = array();
                                                                                                      
                                                                                                          /**
                                                                                                           * Filters the embedded media types that are allowed to be returned from the content blob.
                                                                                                      Severity: Minor
                                                                                                      Found in wp-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 wp_maybe_generate_attachment_metadata has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                                      Open

                                                                                                      function wp_maybe_generate_attachment_metadata( $attachment ) {
                                                                                                          if ( empty( $attachment ) || empty( $attachment->ID ) ) {
                                                                                                              return;
                                                                                                          }
                                                                                                      
                                                                                                      
                                                                                                      Severity: Minor
                                                                                                      Found in wp-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 2 locations. Consider refactoring.
                                                                                                      Open

                                                                                                                  if ( ! empty( $thumb_id ) ) {
                                                                                                                      list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'full' );
                                                                                                                      $track['image']               = compact( 'src', 'width', 'height' );
                                                                                                                      list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' );
                                                                                                                      $track['thumb']               = compact( 'src', 'width', 'height' );
                                                                                                      Severity: Major
                                                                                                      Found in wp-includes/media.php and 1 other location - About 5 hrs to fix
                                                                                                      wp-includes/media.php on lines 4521..4532

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

                                                                                                      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

                                                                                                      Similar blocks of code found in 2 locations. Consider refactoring.
                                                                                                      Open

                                                                                                              if ( ! empty( $id ) ) {
                                                                                                                  list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'full' );
                                                                                                                  $response['image']            = compact( 'src', 'width', 'height' );
                                                                                                                  list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'thumbnail' );
                                                                                                                  $response['thumb']            = compact( 'src', 'width', 'height' );
                                                                                                      Severity: Major
                                                                                                      Found in wp-includes/media.php and 1 other location - About 5 hrs to fix
                                                                                                      wp-includes/media.php on lines 3078..3089

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

                                                                                                      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

                                                                                                      Similar blocks of code found in 2 locations. Consider refactoring.
                                                                                                      Open

                                                                                                      function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
                                                                                                          $image = wp_get_attachment_image_src( $attachment_id, $size );
                                                                                                      
                                                                                                          if ( ! $image ) {
                                                                                                              return false;
                                                                                                      Severity: Major
                                                                                                      Found in wp-includes/media.php and 1 other location - About 3 hrs to fix
                                                                                                      wp-includes/media.php on lines 1518..1536

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

                                                                                                      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

                                                                                                      Similar blocks of code found in 2 locations. Consider refactoring.
                                                                                                      Open

                                                                                                      function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) {
                                                                                                          $image = wp_get_attachment_image_src( $attachment_id, $size );
                                                                                                      
                                                                                                          if ( ! $image ) {
                                                                                                              return false;
                                                                                                      Severity: Major
                                                                                                      Found in wp-includes/media.php and 1 other location - About 3 hrs to fix
                                                                                                      wp-includes/media.php on lines 1268..1286

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

                                                                                                      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

                                                                                                      Similar blocks of code found in 2 locations. Consider refactoring.
                                                                                                      Open

                                                                                                          if ( 'image/avif' === wp_get_image_mime( $filename ) ) {
                                                                                                              $avif_info = wp_get_avif_info( $filename );
                                                                                                      
                                                                                                              $width  = $avif_info['width'];
                                                                                                              $height = $avif_info['height'];
                                                                                                      Severity: Minor
                                                                                                      Found in wp-includes/media.php and 1 other location - About 55 mins to fix
                                                                                                      wp-includes/media.php on lines 5541..5560

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

                                                                                                      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

                                                                                                      Similar blocks of code found in 2 locations. Consider refactoring.
                                                                                                      Open

                                                                                                          if ( 'image/webp' === wp_get_image_mime( $filename ) ) {
                                                                                                              $webp_info = wp_get_webp_info( $filename );
                                                                                                              $width     = $webp_info['width'];
                                                                                                              $height    = $webp_info['height'];
                                                                                                      
                                                                                                      
                                                                                                      Severity: Minor
                                                                                                      Found in wp-includes/media.php and 1 other location - About 55 mins to fix
                                                                                                      wp-includes/media.php on lines 5563..5583

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

                                                                                                      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

                                                                                                      Similar blocks of code found in 2 locations. Consider refactoring.
                                                                                                      Open

                                                                                                          if ( ! $primary ) {
                                                                                                              $videos = get_attached_media( 'video', $post_id );
                                                                                                              if ( empty( $videos ) ) {
                                                                                                                  return;
                                                                                                              }
                                                                                                      Severity: Minor
                                                                                                      Found in wp-includes/media.php and 1 other location - About 30 mins to fix
                                                                                                      wp-includes/media.php on lines 3300..3315

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

                                                                                                      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

                                                                                                      Similar blocks of code found in 2 locations. Consider refactoring.
                                                                                                      Open

                                                                                                          if ( ! $primary ) {
                                                                                                              $audios = get_attached_media( 'audio', $post_id );
                                                                                                      
                                                                                                              if ( empty( $audios ) ) {
                                                                                                                  return;
                                                                                                      Severity: Minor
                                                                                                      Found in wp-includes/media.php and 1 other location - About 30 mins to fix
                                                                                                      wp-includes/media.php on lines 3553..3566

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

                                                                                                      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