WordPress/WordPress

View on GitHub
wp-includes/class-wp-editor.php

Summary

Maintainability
F
2 wks
Test Coverage

Function editor_settings has a Cognitive Complexity of 184 (exceeds 5 allowed). Consider refactoring.
Open

    public static function editor_settings( $editor_id, $set ) {
        if ( empty( self::$first_init ) ) {
            if ( is_admin() ) {
                add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
                add_action( 'admin_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
Severity: Minor
Found in wp-includes/class-wp-editor.php - About 3 days 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

File class-wp-editor.php has 1191 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Facilitates adding of the WordPress editor as used on the Write and Edit screens.
 *
 * @package WordPress
Severity: Major
Found in wp-includes/class-wp-editor.php - About 3 days to fix

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

        public static function editor_settings( $editor_id, $set ) {
            if ( empty( self::$first_init ) ) {
                if ( is_admin() ) {
                    add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
                    add_action( 'admin_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
    Severity: Major
    Found in wp-includes/class-wp-editor.php - About 1 day to fix

      Method get_translation has 254 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function get_translation() {
              if ( empty( self::$translation ) ) {
                  self::$translation = array(
                      // Default TinyMCE strings.
                      'New document'                         => __( 'New document' ),
      Severity: Major
      Found in wp-includes/class-wp-editor.php - About 1 day to fix

        Method editor_js has 119 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function editor_js() {
                global $tinymce_version;
        
                $tmce_on  = ! empty( self::$mce_settings );
                $mce_init = '';
        Severity: Major
        Found in wp-includes/class-wp-editor.php - About 4 hrs to fix

          Function editor has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function editor( $content, $editor_id, $settings = array() ) {
                  $set            = self::parse_settings( $editor_id, $settings );
                  $editor_class   = ' class="' . trim( esc_attr( $set['editor_class'] ) . ' wp-editor-area' ) . '"';
                  $tabindex       = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
                  $default_editor = 'html';
          Severity: Minor
          Found in wp-includes/class-wp-editor.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 editor has 94 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function editor( $content, $editor_id, $settings = array() ) {
                  $set            = self::parse_settings( $editor_id, $settings );
                  $editor_class   = ' class="' . trim( esc_attr( $set['editor_class'] ) . ' wp-editor-area' ) . '"';
                  $tabindex       = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
                  $default_editor = 'html';
          Severity: Major
          Found in wp-includes/class-wp-editor.php - About 3 hrs to fix

            Method wp_link_dialog has 73 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function wp_link_dialog() {
                    // Run once.
                    if ( self::$link_dialog_printed ) {
                        return;
                    }
            Severity: Major
            Found in wp-includes/class-wp-editor.php - About 2 hrs to fix

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

                  public static function print_default_editor_scripts() {
                      $user_can_richedit = user_can_richedit();
              
                      if ( $user_can_richedit ) {
                          $settings = self::default_settings();
              Severity: Major
              Found in wp-includes/class-wp-editor.php - About 2 hrs to fix

                Function editor_js has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static function editor_js() {
                        global $tinymce_version;
                
                        $tmce_on  = ! empty( self::$mce_settings );
                        $mce_init = '';
                Severity: Minor
                Found in wp-includes/class-wp-editor.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 default_settings has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private static function default_settings() {
                        global $tinymce_version;
                
                        $shortcut_labels = array();
                
                
                Severity: Minor
                Found in wp-includes/class-wp-editor.php - About 2 hrs to fix

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

                      public static function parse_settings( $editor_id, $settings ) {
                  
                          /**
                           * Filters the wp_editor() settings.
                           *
                  Severity: Minor
                  Found in wp-includes/class-wp-editor.php - About 1 hr to fix

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

                        public static function parse_settings( $editor_id, $settings ) {
                    
                            /**
                             * Filters the wp_editor() settings.
                             *
                    Severity: Minor
                    Found in wp-includes/class-wp-editor.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_mce_translation has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
                            if ( ! $mce_locale ) {
                                $mce_locale = self::get_mce_locale();
                            }
                    
                    
                    Severity: Minor
                    Found in wp-includes/class-wp-editor.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_link_query has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public static function wp_link_query( $args = array() ) {
                            $pts      = get_post_types( array( 'public' => true ), 'objects' );
                            $pt_names = array_keys( $pts );
                    
                            $query = array(
                    Severity: Minor
                    Found in wp-includes/class-wp-editor.php - About 1 hr to fix

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

                          public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
                              if ( ! $mce_locale ) {
                                  $mce_locale = self::get_mce_locale();
                              }
                      
                      
                      Severity: Minor
                      Found in wp-includes/class-wp-editor.php - About 1 hr to fix

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

                            private static function _parse_init( $init ) {
                                $options = '';
                        
                                foreach ( $init as $key => $value ) {
                                    if ( is_bool( $value ) ) {
                        Severity: Minor
                        Found in wp-includes/class-wp-editor.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

                        Consider simplifying this complex logical expression.
                        Open

                                    if ( is_bool( $value ) ) {
                                        $val      = $value ? 'true' : 'false';
                                        $options .= $key . ':' . $val . ',';
                                        continue;
                                    } elseif ( ! empty( $value ) && is_string( $value ) && (
                        Severity: Major
                        Found in wp-includes/class-wp-editor.php - About 1 hr to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                          if ( ! empty( $strings ) ) {
                                                              $ext_plugins .= "\n" . $strings . "\n";
                                                          }
                          Severity: Major
                          Found in wp-includes/class-wp-editor.php - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                            if ( @is_file( $path . $mce_locale . '_dlg.js' ) ) {
                                                                $strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n";
                                                            }
                            Severity: Major
                            Found in wp-includes/class-wp-editor.php - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                              if ( @is_file( $path ) && @is_readable( $path ) ) {
                                                                  include_once $path;
                                                                  $ext_plugins   .= $strings . "\n";
                                                                  $loaded_langs[] = $name;
                                                              }
                              Severity: Major
                              Found in wp-includes/class-wp-editor.php - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                            if ( str_contains( $url, ',' ) ) {
                                                                $editor_styles[ $key ] = str_replace( ',', '%2C', $url );
                                                            }
                                Severity: Major
                                Found in wp-includes/class-wp-editor.php - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                                  if ( 'en' !== $mce_locale && empty( $strings ) ) {
                                                                      if ( @is_file( $path . 'en.js' ) ) {
                                                                          $str1     = @file_get_contents( $path . 'en.js' );
                                                                          $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
                                                                      }
                                  Severity: Major
                                  Found in wp-includes/class-wp-editor.php - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                                    if ( @is_file( $path . $mce_locale . '.js' ) ) {
                                                                        $strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n";
                                                                    }
                                    Severity: Major
                                    Found in wp-includes/class-wp-editor.php - About 45 mins to fix

                                      Avoid deeply nested control flow statements.
                                      Open

                                                                      if ( ! $path ) {
                                                                          continue;
                                                                      }
                                      Severity: Major
                                      Found in wp-includes/class-wp-editor.php - About 45 mins to fix

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

                                            public static function enqueue_scripts( $default_scripts = false ) {
                                                if ( $default_scripts || self::$has_tinymce ) {
                                                    wp_enqueue_script( 'editor' );
                                                }
                                        
                                        
                                        Severity: Minor
                                        Found in wp-includes/class-wp-editor.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 print_default_editor_scripts has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                            public static function print_default_editor_scripts() {
                                                $user_can_richedit = user_can_richedit();
                                        
                                                if ( $user_can_richedit ) {
                                                    $settings = self::default_settings();
                                        Severity: Minor
                                        Found in wp-includes/class-wp-editor.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

                                                foreach ( $init as $key => $value ) {
                                                    if ( is_bool( $value ) ) {
                                                        $val      = $value ? 'true' : 'false';
                                                        $options .= $key . ':' . $val . ',';
                                                        continue;
                                        Severity: Major
                                        Found in wp-includes/class-wp-editor.php and 1 other location - About 5 hrs to fix
                                        wp-includes/script-loader.php on lines 624..637

                                        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

                                        There are no issues that match your filters.

                                        Category
                                        Status