wikimedia/mediawiki-core

View on GitHub
includes/json/FormatJson.php

Summary

Maintainability
C
1 day
Test Coverage

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

    public static function stripComments( $json ) {
        // Ensure we have a string
        $str = (string)$json;
        $buffer = '';
        $maxLen = strlen( $str );
Severity: Minor
Found in includes/json/FormatJson.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 parse has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    public static function parse( $value, $options = 0 ) {
        if ( $options & self::STRIP_COMMENTS ) {
            $value = self::stripComments( $value );
        }
        $assoc = ( $options & self::FORCE_ASSOC ) !== 0;
Severity: Minor
Found in includes/json/FormatJson.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 parse has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function parse( $value, $options = 0 ) {
        if ( $options & self::STRIP_COMMENTS ) {
            $value = self::stripComments( $value );
        }
        $assoc = ( $options & self::FORCE_ASSOC ) !== 0;
Severity: Minor
Found in includes/json/FormatJson.php - About 1 hr to fix

    Method stripComments has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function stripComments( $json ) {
            // Ensure we have a string
            $str = (string)$json;
            $buffer = '';
            $maxLen = strlen( $str );
    Severity: Minor
    Found in includes/json/FormatJson.php - About 1 hr to fix

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

          public static function encode( $value, $pretty = false, $escaping = 0 ) {
              // PHP escapes '/' to prevent breaking out of inline script blocks using '</script>',
              // which is hardly useful when '<' and '>' are escaped (and inadequate), and such
              // escaping negatively impacts the human readability of URLs and similar strings.
              $options = JSON_UNESCAPED_SLASHES;
      Severity: Minor
      Found in includes/json/FormatJson.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

      There are no issues that match your filters.

      Category
      Status