WordPress/WordPress

View on GitHub
wp-includes/theme.php

Summary

Maintainability
F
3 wks
Test Coverage

File theme.php has 2430 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Theme, template, and stylesheet functions.
 *
 * @package WordPress
Severity: Major
Found in wp-includes/theme.php - About 6 days to fix

    Method create_initial_theme_features has 381 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function create_initial_theme_features() {
        register_theme_feature(
            'align-wide',
            array(
                'description'  => __( 'Whether theme opts in to wide alignment CSS class.' ),
    Severity: Major
    Found in wp-includes/theme.php - About 1 day to fix

      Method get_theme_starter_content has 277 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function get_theme_starter_content() {
          $theme_support = get_theme_support( 'starter-content' );
          if ( is_array( $theme_support ) && ! empty( $theme_support[0] ) && is_array( $theme_support[0] ) ) {
              $config = $theme_support[0];
          } else {
      Severity: Major
      Found in wp-includes/theme.php - About 1 day to fix

        Function search_theme_directories has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
        Open

        function search_theme_directories( $force = false ) {
            global $wp_theme_directories;
            static $found_themes = null;
        
            if ( empty( $wp_theme_directories ) ) {
        Severity: Minor
        Found in wp-includes/theme.php - About 1 day to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function get_theme_starter_content has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
        Open

        function get_theme_starter_content() {
            $theme_support = get_theme_support( 'starter-content' );
            if ( is_array( $theme_support ) && ! empty( $theme_support[0] ) && is_array( $theme_support[0] ) ) {
                $config = $theme_support[0];
            } else {
        Severity: Minor
        Found in wp-includes/theme.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 add_theme_support has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
        Open

        function add_theme_support( $feature, ...$args ) {
            global $_wp_theme_features;
        
            if ( ! $args ) {
                $args = true;
        Severity: Minor
        Found in wp-includes/theme.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 add_theme_support has 179 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function add_theme_support( $feature, ...$args ) {
            global $_wp_theme_features;
        
            if ( ! $args ) {
                $args = true;
        Severity: Major
        Found in wp-includes/theme.php - About 7 hrs to fix

          Method search_theme_directories has 93 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function search_theme_directories( $force = false ) {
              global $wp_theme_directories;
              static $found_themes = null;
          
              if ( empty( $wp_theme_directories ) ) {
          Severity: Major
          Found in wp-includes/theme.php - About 3 hrs to fix

            Function wp_get_themes has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
            Open

            function wp_get_themes( $args = array() ) {
                global $wp_theme_directories;
            
                $defaults = array(
                    'errors'  => false,
            Severity: Minor
            Found in wp-includes/theme.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 register_theme_feature has 86 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function register_theme_feature( $feature, $args = array() ) {
                global $_wp_registered_theme_features;
            
                if ( ! is_array( $_wp_registered_theme_features ) ) {
                    $_wp_registered_theme_features = array();
            Severity: Major
            Found in wp-includes/theme.php - About 3 hrs to fix

              Method switch_theme has 75 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function switch_theme( $stylesheet ) {
                  global $wp_theme_directories, $wp_customize, $sidebars_widgets, $wp_registered_sidebars;
              
                  $requirements = validate_theme_requirements( $stylesheet );
                  if ( is_wp_error( $requirements ) ) {
              Severity: Major
              Found in wp-includes/theme.php - About 3 hrs to fix

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

                function get_editor_stylesheets() {
                    $stylesheets = array();
                    // Load editor_style.css if the active theme supports it.
                    if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) {
                        $editor_styles = $GLOBALS['editor_styles'];
                Severity: Minor
                Found in wp-includes/theme.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 switch_theme has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
                Open

                function switch_theme( $stylesheet ) {
                    global $wp_theme_directories, $wp_customize, $sidebars_widgets, $wp_registered_sidebars;
                
                    $requirements = validate_theme_requirements( $stylesheet );
                    if ( is_wp_error( $requirements ) ) {
                Severity: Minor
                Found in wp-includes/theme.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 register_theme_feature has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                Open

                function register_theme_feature( $feature, $args = array() ) {
                    global $_wp_registered_theme_features;
                
                    if ( ! is_array( $_wp_registered_theme_features ) ) {
                        $_wp_registered_theme_features = array();
                Severity: Minor
                Found in wp-includes/theme.php - About 2 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

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

                function get_header_image_tag( $attr = array() ) {
                    $header      = get_custom_header();
                    $header->url = get_header_image();
                
                    if ( ! $header->url ) {
                Severity: Minor
                Found in wp-includes/theme.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_customize_include has 63 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function _wp_customize_include() {
                
                    $is_customize_admin_page = ( is_admin() && 'customize.php' === basename( $_SERVER['PHP_SELF'] ) );
                    $should_include          = (
                        $is_customize_admin_page
                Severity: Major
                Found in wp-includes/theme.php - About 2 hrs to fix

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

                  function get_custom_header() {
                      global $_wp_default_headers;
                  
                      if ( is_random_header_image() ) {
                          $data = _get_random_header_data();
                  Severity: Minor
                  Found in wp-includes/theme.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 get_header_image_tag has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function get_header_image_tag( $attr = array() ) {
                      $header      = get_custom_header();
                      $header->url = get_header_image();
                  
                      if ( ! $header->url ) {
                  Severity: Major
                  Found in wp-includes/theme.php - About 2 hrs to fix

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

                    function _wp_keep_alive_customize_changeset_dependent_auto_drafts( $new_status, $old_status, $post ) {
                        global $wpdb;
                        unset( $old_status );
                    
                        // Short-circuit if not a changeset or if the changeset was published.
                    Severity: Minor
                    Found in wp-includes/theme.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 _custom_background_cb has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                    Open

                    function _custom_background_cb() {
                        // $background is the saved custom image, or the default image.
                        $background = set_url_scheme( get_background_image() );
                    
                        /*
                    Severity: Minor
                    Found in wp-includes/theme.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_get_themes has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function wp_get_themes( $args = array() ) {
                        global $wp_theme_directories;
                    
                        $defaults = array(
                            'errors'  => false,
                    Severity: Major
                    Found in wp-includes/theme.php - About 2 hrs to fix

                      Method _custom_background_cb has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function _custom_background_cb() {
                          // $background is the saved custom image, or the default image.
                          $background = set_url_scheme( get_background_image() );
                      
                          /*
                      Severity: Minor
                      Found in wp-includes/theme.php - About 1 hr to fix

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

                        function get_theme_root_uri( $stylesheet_or_template = '', $theme_root = '' ) {
                            global $wp_theme_directories;
                        
                            if ( $stylesheet_or_template && ! $theme_root ) {
                                $theme_root = get_raw_theme_root( $stylesheet_or_template );
                        Severity: Minor
                        Found in wp-includes/theme.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 _get_random_header_data has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                        Open

                        function _get_random_header_data() {
                            global $_wp_default_headers;
                            static $_wp_random_header = null;
                        
                            if ( empty( $_wp_random_header ) ) {
                        Severity: Minor
                        Found in wp-includes/theme.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_update_custom_css_post has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        function wp_update_custom_css_post( $css, $args = array() ) {
                            $args = wp_parse_args(
                                $args,
                                array(
                                    'preprocessed' => '',
                        Severity: Minor
                        Found in wp-includes/theme.php - About 1 hr to fix

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

                          function _remove_theme_support( $feature ) {
                              global $_wp_theme_features;
                          
                              switch ( $feature ) {
                                  case 'custom-header-uploads':
                          Severity: Minor
                          Found in wp-includes/theme.php - About 1 hr to fix

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

                            function _remove_theme_support( $feature ) {
                                global $_wp_theme_features;
                            
                                switch ( $feature ) {
                                    case 'custom-header-uploads':
                            Severity: Minor
                            Found in wp-includes/theme.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_customize_include has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                            Open

                            function _wp_customize_include() {
                            
                                $is_customize_admin_page = ( is_admin() && 'customize.php' === basename( $_SERVER['PHP_SELF'] ) );
                                $should_include          = (
                                    $is_customize_admin_page
                            Severity: Minor
                            Found in wp-includes/theme.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_update_custom_css_post has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                            Open

                            function wp_update_custom_css_post( $css, $args = array() ) {
                                $args = wp_parse_args(
                                    $args,
                                    array(
                                        'preprocessed' => '',
                            Severity: Minor
                            Found in wp-includes/theme.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 get_uploaded_header_images has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            function get_uploaded_header_images() {
                                $header_images = array();
                            
                                // @todo Caching.
                                $headers = get_posts(
                            Severity: Minor
                            Found in wp-includes/theme.php - About 1 hr to fix

                              Method _wp_keep_alive_customize_changeset_dependent_auto_drafts has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              function _wp_keep_alive_customize_changeset_dependent_auto_drafts( $new_status, $old_status, $post ) {
                                  global $wpdb;
                                  unset( $old_status );
                              
                                  // Short-circuit if not a changeset or if the changeset was published.
                              Severity: Minor
                              Found in wp-includes/theme.php - About 1 hr to fix

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

                                function validate_theme_requirements( $stylesheet ) {
                                    $theme = wp_get_theme( $stylesheet );
                                
                                    $requirements = array(
                                        'requires'     => ! empty( $theme->get( 'RequiresWP' ) ) ? $theme->get( 'RequiresWP' ) : '',
                                Severity: Minor
                                Found in wp-includes/theme.php - About 1 hr to fix

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

                                  function _get_random_header_data() {
                                      global $_wp_default_headers;
                                      static $_wp_random_header = null;
                                  
                                      if ( empty( $_wp_random_header ) ) {
                                  Severity: Minor
                                  Found in wp-includes/theme.php - About 1 hr to fix

                                    Method get_custom_header has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                    function get_custom_header() {
                                        global $_wp_default_headers;
                                    
                                        if ( is_random_header_image() ) {
                                            $data = _get_random_header_data();
                                    Severity: Minor
                                    Found in wp-includes/theme.php - About 1 hr to fix

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

                                      function wp_get_custom_css_post( $stylesheet = '' ) {
                                          if ( empty( $stylesheet ) ) {
                                              $stylesheet = get_stylesheet();
                                          }
                                      
                                      
                                      Severity: Minor
                                      Found in wp-includes/theme.php - About 1 hr to fix

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

                                        function _wp_customize_publish_changeset( $new_status, $old_status, $changeset_post ) {
                                            global $wp_customize;
                                        
                                            $is_publishing_changeset = (
                                                'customize_changeset' === $changeset_post->post_type
                                        Severity: Minor
                                        Found in wp-includes/theme.php - About 1 hr to fix

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

                                          function get_editor_stylesheets() {
                                              $stylesheets = array();
                                              // Load editor_style.css if the active theme supports it.
                                              if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) {
                                                  $editor_styles = $GLOBALS['editor_styles'];
                                          Severity: Minor
                                          Found in wp-includes/theme.php - About 1 hr to fix

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

                                            function validate_current_theme() {
                                                /**
                                                 * Filters whether to validate the active theme.
                                                 *
                                                 * @since 2.7.0
                                            Severity: Minor
                                            Found in wp-includes/theme.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 current_theme_supports has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                            Open

                                            function current_theme_supports( $feature, ...$args ) {
                                                global $_wp_theme_features;
                                            
                                                if ( 'custom-header-uploads' === $feature ) {
                                                    return current_theme_supports( 'custom-header', 'uploads' );
                                            Severity: Minor
                                            Found in wp-includes/theme.php - About 1 hr to fix

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

                                              function get_uploaded_header_images() {
                                                  $header_images = array();
                                              
                                                  // @todo Caching.
                                                  $headers = get_posts(
                                              Severity: Minor
                                              Found in wp-includes/theme.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 get_raw_theme_root has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                              function get_raw_theme_root( $stylesheet_or_template, $skip_cache = false ) {
                                                  global $wp_theme_directories;
                                              
                                                  if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) {
                                                      return '/themes';
                                              Severity: Minor
                                              Found in wp-includes/theme.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 is_random_header_image has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                              function is_random_header_image( $type = 'any' ) {
                                                  $header_image_mod = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) );
                                              
                                                  if ( 'any' === $type ) {
                                                      if ( 'random-default-image' === $header_image_mod
                                              Severity: Minor
                                              Found in wp-includes/theme.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 _custom_header_background_just_in_time has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                              function _custom_header_background_just_in_time() {
                                                  global $custom_image_header, $custom_background;
                                              
                                                  if ( current_theme_supports( 'custom-header' ) ) {
                                                      // In case any constants were defined after an add_custom_image_header() call, re-run.
                                              Severity: Minor
                                              Found in wp-includes/theme.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_get_custom_css_post has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                              function wp_get_custom_css_post( $stylesheet = '' ) {
                                                  if ( empty( $stylesheet ) ) {
                                                      $stylesheet = get_stylesheet();
                                                  }
                                              
                                              
                                              Severity: Minor
                                              Found in wp-includes/theme.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 get_theme_root has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                              function get_theme_root( $stylesheet_or_template = '' ) {
                                                  global $wp_theme_directories;
                                              
                                                  $theme_root = '';
                                              
                                              
                                              Severity: Minor
                                              Found in wp-includes/theme.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_theme_mods has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                              function get_theme_mods() {
                                                  $theme_slug = get_option( 'stylesheet' );
                                                  $mods       = get_option( "theme_mods_$theme_slug" );
                                              
                                                  if ( false === $mods ) {
                                              Severity: Minor
                                              Found in wp-includes/theme.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 current_theme_supports has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                              Open

                                              function current_theme_supports( $feature, ...$args ) {
                                                  global $_wp_theme_features;
                                              
                                                  if ( 'custom-header-uploads' === $feature ) {
                                                      return current_theme_supports( 'custom-header', 'uploads' );
                                              Severity: Minor
                                              Found in wp-includes/theme.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/theme.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                            return ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) && $_wp_theme_features[ $feature ][0][ $args[0] ] );
                                                Severity: Major
                                                Found in wp-includes/theme.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                              return in_array( $type, $_wp_theme_features[ $feature ][0], true );
                                                  Severity: Major
                                                  Found in wp-includes/theme.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

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

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                  return in_array( $content_type, $_wp_theme_features[ $feature ][0], true );
                                                      Severity: Major
                                                      Found in wp-includes/theme.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

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

                                                          Avoid too many return statements within this method.
                                                          Open

                                                              return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
                                                          Severity: Major
                                                          Found in wp-includes/theme.php - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                        return $_wp_theme_features[ $feature ];
                                                            Severity: Major
                                                            Found in wp-includes/theme.php - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                          return new WP_Error(
                                                                              'missing_schema_properties',
                                                                              __( 'When registering an "object" feature, the feature\'s schema must include the "properties" keyword.' )
                                                                          );
                                                              Severity: Major
                                                              Found in wp-includes/theme.php - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                            return new WP_Error(
                                                                                'invalid_rest_prepare_callback',
                                                                                sprintf(
                                                                                    /* translators: %s: prepare_callback */
                                                                                    __( 'The "%s" must be a callable function.' ),
                                                                Severity: Major
                                                                Found in wp-includes/theme.php - About 30 mins to fix

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

                                                                  function check_theme_switched() {
                                                                      $stylesheet = get_option( 'theme_switched' );
                                                                  
                                                                      if ( $stylesheet ) {
                                                                          $old_theme = wp_get_theme( $stylesheet );
                                                                  Severity: Minor
                                                                  Found in wp-includes/theme.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 register_theme_directory has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                  Open

                                                                  function register_theme_directory( $directory ) {
                                                                      global $wp_theme_directories;
                                                                  
                                                                      if ( ! file_exists( $directory ) ) {
                                                                          // Try prepending as the theme directory could be relative to the content directory.
                                                                  Severity: Minor
                                                                  Found in wp-includes/theme.php - About 25 mins to fix

                                                                  Cognitive Complexity

                                                                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                                                  A method's cognitive complexity is based on a few simple rules:

                                                                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                                                  • Code is considered more complex for each "break in the linear flow of the code"
                                                                  • Code is considered more complex when "flow breaking structures are nested"

                                                                  Further reading

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

                                                                      register_theme_feature(
                                                                          'editor-font-sizes',
                                                                          array(
                                                                              'type'         => 'array',
                                                                              'description'  => __( 'Custom font sizes if defined by the theme.' ),
                                                                  Severity: Minor
                                                                  Found in wp-includes/theme.php and 2 other locations - About 40 mins to fix
                                                                  wp-includes/theme.php on lines 4154..4178
                                                                  wp-includes/theme.php on lines 4204..4228

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

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

                                                                      register_theme_feature(
                                                                          'editor-color-palette',
                                                                          array(
                                                                              'type'         => 'array',
                                                                              'description'  => __( 'Custom color palette if defined by the theme.' ),
                                                                  Severity: Minor
                                                                  Found in wp-includes/theme.php and 2 other locations - About 40 mins to fix
                                                                  wp-includes/theme.php on lines 4179..4203
                                                                  wp-includes/theme.php on lines 4204..4228

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

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

                                                                      register_theme_feature(
                                                                          'editor-gradient-presets',
                                                                          array(
                                                                              'type'         => 'array',
                                                                              'description'  => __( 'Custom gradient presets if defined by the theme.' ),
                                                                  Severity: Minor
                                                                  Found in wp-includes/theme.php and 2 other locations - About 40 mins to fix
                                                                  wp-includes/theme.php on lines 4154..4178
                                                                  wp-includes/theme.php on lines 4179..4203

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

                                                                  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