WordPress/WordPress

View on GitHub
wp-includes/kses.php

Summary

Maintainability
F
1 wk
Test Coverage

File kses.php has 1601 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * kses 0.2.2 - HTML/XHTML filter that only allows some elements and attributes
 * Copyright (C) 2002, 2003, 2005  Ulf Harnhammar
 *
Severity: Major
Found in wp-includes/kses.php - About 4 days to fix

    Method safecss_filter_attr has 232 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function safecss_filter_attr( $css, $deprecated = '' ) {
        if ( ! empty( $deprecated ) ) {
            _deprecated_argument( __FUNCTION__, '2.8.1' ); // Never implemented.
        }
    
    
    Severity: Major
    Found in wp-includes/kses.php - About 1 day to fix

      Function safecss_filter_attr has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
      Open

      function safecss_filter_attr( $css, $deprecated = '' ) {
          if ( ! empty( $deprecated ) ) {
              _deprecated_argument( __FUNCTION__, '2.8.1' ); // Never implemented.
          }
      
      
      Severity: Minor
      Found in wp-includes/kses.php - About 7 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Function wp_kses_hair has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
      Open

      function wp_kses_hair( $attr, $allowed_protocols ) {
          $attrarr  = array();
          $mode     = 0;
          $attrname = '';
          $uris     = wp_kses_uri_attributes();
      Severity: Minor
      Found in wp-includes/kses.php - About 6 hrs to fix

      Cognitive Complexity

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

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

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

      Further reading

      Method wp_kses_hair has 103 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function wp_kses_hair( $attr, $allowed_protocols ) {
          $attrarr  = array();
          $mode     = 0;
          $attrname = '';
          $uris     = wp_kses_uri_attributes();
      Severity: Major
      Found in wp-includes/kses.php - About 4 hrs to fix

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

        function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) {
            $ok = true;
        
            switch ( strtolower( $checkname ) ) {
                case 'maxlen':
        Severity: Minor
        Found in wp-includes/kses.php - About 2 hrs to fix

        Cognitive Complexity

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

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

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

        Further reading

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

        function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowed_html ) {
            $name_low    = strtolower( $name );
            $element_low = strtolower( $element );
        
            if ( ! isset( $allowed_html[ $element_low ] ) ) {
        Severity: Minor
        Found in wp-includes/kses.php - About 2 hrs to fix

        Cognitive Complexity

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

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

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

        Further reading

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

        function wp_kses_one_attr( $attr, $element ) {
            $uris              = wp_kses_uri_attributes();
            $allowed_html      = wp_kses_allowed_html( 'post' );
            $allowed_protocols = wp_allowed_protocols();
            $attr              = wp_kses_no_null( $attr, array( 'slash_zero' => 'keep' ) );
        Severity: Minor
        Found in wp-includes/kses.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_kses_check_attr_val has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function wp_kses_check_attr_val( $value, $vless, $checkname, $checkvalue ) {
            $ok = true;
        
            switch ( strtolower( $checkname ) ) {
                case 'maxlen':
        Severity: Minor
        Found in wp-includes/kses.php - About 1 hr to fix

          Method wp_kses_attr_check has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowed_html ) {
              $name_low    = strtolower( $name );
              $element_low = strtolower( $element );
          
              if ( ! isset( $allowed_html[ $element_low ] ) ) {
          Severity: Minor
          Found in wp-includes/kses.php - About 1 hr to fix

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

            function wp_kses_one_attr( $attr, $element ) {
                $uris              = wp_kses_uri_attributes();
                $allowed_html      = wp_kses_allowed_html( 'post' );
                $allowed_protocols = wp_allowed_protocols();
                $attr              = wp_kses_no_null( $attr, array( 'slash_zero' => 'keep' ) );
            Severity: Minor
            Found in wp-includes/kses.php - About 1 hr to fix

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

              function wp_kses_attr( $element, $attr, $allowed_html, $allowed_protocols ) {
                  if ( ! is_array( $allowed_html ) ) {
                      $allowed_html = wp_kses_allowed_html( $allowed_html );
                  }
              
              
              Severity: Minor
              Found in wp-includes/kses.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_kses_attr has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function wp_kses_attr( $element, $attr, $allowed_html, $allowed_protocols ) {
                  if ( ! is_array( $allowed_html ) ) {
                      $allowed_html = wp_kses_allowed_html( $allowed_html );
                  }
              
              
              Severity: Minor
              Found in wp-includes/kses.php - About 1 hr to fix

                Method wp_kses_allowed_html has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function wp_kses_allowed_html( $context = '' ) {
                    global $allowedposttags, $allowedtags, $allowedentitynames;
                
                    if ( is_array( $context ) ) {
                        // When `$context` is an array it's actually an array of allowed HTML elements and attributes.
                Severity: Minor
                Found in wp-includes/kses.php - About 1 hr to fix

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

                  function wp_kses_hair_parse( $attr ) {
                      if ( '' === $attr ) {
                          return array();
                      }
                  
                  
                  Severity: Minor
                  Found in wp-includes/kses.php - About 1 hr to fix

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

                    function wp_kses_split2( $content, $allowed_html, $allowed_protocols ) {
                        $content = wp_kses_stripslashes( $content );
                    
                        // It matched a ">" character.
                        if ( ! str_starts_with( $content, '<' ) ) {
                    Severity: Minor
                    Found in wp-includes/kses.php - About 1 hr to fix

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

                      function wp_kses_bad_protocol_once( $content, $allowed_protocols, $count = 1 ) {
                          $content  = preg_replace( '/(&#0*58(?![;0-9])|&#x0*3a(?![;a-f0-9]))/i', '$1;', $content );
                          $content2 = preg_split( '/:|&#0*58;|&#x0*3a;|&colon;/i', $content, 2 );
                      
                          if ( isset( $content2[1] ) && ! preg_match( '%/\?%', $content2[0] ) ) {
                      Severity: Minor
                      Found in wp-includes/kses.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_add_global_attributes has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function _wp_add_global_attributes( $value ) {
                          $global_attributes = array(
                              'aria-controls'    => true,
                              'aria-current'     => true,
                              'aria-describedby' => true,
                      Severity: Minor
                      Found in wp-includes/kses.php - About 1 hr to fix

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

                        function wp_kses_split2( $content, $allowed_html, $allowed_protocols ) {
                            $content = wp_kses_stripslashes( $content );
                        
                            // It matched a ">" character.
                            if ( ! str_starts_with( $content, '<' ) ) {
                        Severity: Minor
                        Found in wp-includes/kses.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_kses_attr_check has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowed_html ) {
                        Severity: Minor
                        Found in wp-includes/kses.php - About 45 mins to fix

                          Avoid too many return statements within this method.
                          Open

                              return "<$element$attr2$xhtml_slash>";
                          Severity: Major
                          Found in wp-includes/kses.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return apply_filters( 'wp_kses_allowed_html', $allowedtags, $context );
                            Severity: Major
                            Found in wp-includes/kses.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

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

                                Avoid too many return statements within this method.
                                Open

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

                                  Avoid too many return statements within this method.
                                  Open

                                      return wp_kses_attr( $elem, $attrlist, $allowed_html, $allowed_protocols );
                                  Severity: Major
                                  Found in wp-includes/kses.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                return apply_filters( 'wp_kses_allowed_html', $allowedentitynames, $context );
                                    Severity: Major
                                    Found in wp-includes/kses.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                              return "</$elem>";
                                      Severity: Major
                                      Found in wp-includes/kses.php - About 30 mins to fix

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

                                        function valid_unicode( $i ) {
                                            $i = (int) $i;
                                        
                                            return ( 0x9 === $i || 0xa === $i || 0xd === $i ||
                                                ( 0x20 <= $i && $i <= 0xd7ff ) ||
                                        Severity: Minor
                                        Found in wp-includes/kses.php - About 25 mins to fix

                                        Cognitive Complexity

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

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

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

                                        Further reading

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

                                        function wp_kses_bad_protocol_once2( $scheme, $allowed_protocols ) {
                                            $scheme = wp_kses_decode_entities( $scheme );
                                            $scheme = preg_replace( '/\s/', '', $scheme );
                                            $scheme = wp_kses_no_null( $scheme );
                                            $scheme = strtolower( $scheme );
                                        Severity: Minor
                                        Found in wp-includes/kses.php - About 25 mins to fix

                                        Cognitive Complexity

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

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

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

                                        Further reading

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

                                                        if ( preg_match( '%^"([^"]*)"(\s+|/?$)%', $attr, $match ) ) {
                                                            // "value"
                                                            $thisval = $match[1];
                                                            if ( in_array( strtolower( $attrname ), $uris, true ) ) {
                                                                $thisval = wp_kses_bad_protocol( $thisval, $allowed_protocols );
                                        Severity: Major
                                        Found in wp-includes/kses.php and 1 other location - About 4 hrs to fix
                                        wp-includes/kses.php on lines 1402..1422

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

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

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

                                                        if ( preg_match( "%^'([^']*)'(\s+|/?$)%", $attr, $match ) ) {
                                                            // 'value'
                                                            $thisval = $match[1];
                                                            if ( in_array( strtolower( $attrname ), $uris, true ) ) {
                                                                $thisval = wp_kses_bad_protocol( $thisval, $allowed_protocols );
                                        Severity: Major
                                        Found in wp-includes/kses.php and 1 other location - About 4 hrs to fix
                                        wp-includes/kses.php on lines 1380..1400

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

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

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

                                                'td'         => array(
                                                    'abbr'    => true,
                                                    'align'   => true,
                                                    'axis'    => true,
                                                    'bgcolor' => true,
                                        Severity: Major
                                        Found in wp-includes/kses.php and 1 other location - About 1 hr to fix
                                        wp-includes/kses.php on lines 325..340

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

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

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

                                                'th'         => array(
                                                    'abbr'    => true,
                                                    'align'   => true,
                                                    'axis'    => true,
                                                    'bgcolor' => true,
                                        Severity: Major
                                        Found in wp-includes/kses.php and 1 other location - About 1 hr to fix
                                        wp-includes/kses.php on lines 296..311

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

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

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

                                                'img'        => array(
                                                    'alt'      => true,
                                                    'align'    => true,
                                                    'border'   => true,
                                                    'height'   => true,
                                        Severity: Minor
                                        Found in wp-includes/kses.php and 1 other location - About 30 mins to fix
                                        wp-admin/includes/theme-install.php on lines 39..51

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

                                        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