wikimedia/mediawiki-core

View on GitHub
includes/GlobalFunctions.php

Summary

Maintainability
F
1 wk
Test Coverage

File GlobalFunctions.php has 1024 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Global functions used everywhere.
 *
 * This program is free software; you can redistribute it and/or modify
Severity: Major
Found in includes/GlobalFunctions.php - About 2 days to fix

    Function wfArrayToCgi has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

    function wfArrayToCgi( $array1, $array2 = null, $prefix = '' ) {
        if ( $array2 !== null ) {
            $array1 += $array2;
        }
    
    
    Severity: Minor
    Found in includes/GlobalFunctions.php - About 4 hrs to fix

    Cognitive Complexity

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

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

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

    Further reading

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

    function wfCgiToArray( $query ) {
        if ( isset( $query[0] ) && $query[0] == '?' ) {
            $query = substr( $query, 1 );
        }
        $bits = explode( '&', $query );
    Severity: Minor
    Found in includes/GlobalFunctions.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 wfEscapeWikiText has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function wfEscapeWikiText( $input ): string {
        global $wgEnableMagicLinks;
        static $repl = null, $repl2 = null, $repl3 = null, $repl4 = null;
        if ( $repl === null || defined( 'MW_PARSER_TEST' ) || defined( 'MW_PHPUNIT_TEST' ) ) {
            // Tests depend upon being able to change $wgEnableMagicLinks, so don't cache
    Severity: Major
    Found in includes/GlobalFunctions.php - About 2 hrs to fix

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

      function wfResetOutputBuffers( $resetGzipEncoding = true ) {
          while ( $status = ob_get_status() ) {
              if ( isset( $status['flags'] ) ) {
                  $flags = PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_REMOVABLE;
                  $deleteable = ( $status['flags'] & $flags ) === $flags;
      Severity: Minor
      Found in includes/GlobalFunctions.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 wfThumbIsStandard has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

      function wfThumbIsStandard( File $file, array $params ) {
          global $wgThumbLimits, $wgImageLimits, $wgResponsiveImages;
      
          $multipliers = [ 1 ];
          if ( $wgResponsiveImages ) {
      Severity: Minor
      Found in includes/GlobalFunctions.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 wfMerge has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function wfMerge(
          string $old,
          string $mine,
          string $yours,
          ?string &$simplisticMergeAttempt,
      Severity: Major
      Found in includes/GlobalFunctions.php - About 2 hrs to fix

        Method wfThumbIsStandard has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function wfThumbIsStandard( File $file, array $params ) {
            global $wgThumbLimits, $wgImageLimits, $wgResponsiveImages;
        
            $multipliers = [ 1 ];
            if ( $wgResponsiveImages ) {
        Severity: Major
        Found in includes/GlobalFunctions.php - About 2 hrs to fix

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

          function wfRecursiveRemoveDir( $dir ) {
              // taken from https://www.php.net/manual/en/function.rmdir.php#98622
              if ( is_dir( $dir ) ) {
                  $objects = scandir( $dir );
                  foreach ( $objects as $object ) {
          Severity: Minor
          Found in includes/GlobalFunctions.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 wfClientAcceptsGzip has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          function wfClientAcceptsGzip( $force = false ) {
              static $result = null;
              if ( $result === null || $force ) {
                  $result = false;
                  if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
          Severity: Minor
          Found in includes/GlobalFunctions.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 wfEscapeWikiText has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          function wfEscapeWikiText( $input ): string {
              global $wgEnableMagicLinks;
              static $repl = null, $repl2 = null, $repl3 = null, $repl4 = null;
              if ( $repl === null || defined( 'MW_PARSER_TEST' ) || defined( 'MW_PHPUNIT_TEST' ) ) {
                  // Tests depend upon being able to change $wgEnableMagicLinks, so don't cache
          Severity: Minor
          Found in includes/GlobalFunctions.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 wfCgiToArray has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function wfCgiToArray( $query ) {
              if ( isset( $query[0] ) && $query[0] == '?' ) {
                  $query = substr( $query, 1 );
              }
              $bits = explode( '&', $query );
          Severity: Minor
          Found in includes/GlobalFunctions.php - About 1 hr to fix

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

            function wfArrayToCgi( $array1, $array2 = null, $prefix = '' ) {
                if ( $array2 !== null ) {
                    $array1 += $array2;
                }
            
            
            Severity: Minor
            Found in includes/GlobalFunctions.php - About 1 hr to fix

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

              function wfArrayDiff2( $arr1, $arr2 ) {
                  /**
                   * @param string|array $a
                   * @param string|array $b
                   */
              Severity: Minor
              Found in includes/GlobalFunctions.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 wfArrayDiff2 has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function wfArrayDiff2( $arr1, $arr2 ) {
                  /**
                   * @param string|array $a
                   * @param string|array $b
                   */
              Severity: Minor
              Found in includes/GlobalFunctions.php - About 1 hr to fix

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

                function wfGetLangObj( $langcode = false ) {
                    wfDeprecated( __FUNCTION__, '1.41' );
                    # Identify which language to get or create a language object for.
                    # Using is_object here due to Stub objects.
                    if ( is_object( $langcode ) ) {
                Severity: Minor
                Found in includes/GlobalFunctions.php - About 1 hr to fix

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

                  function wfAppendQuery( $url, $query ) {
                      if ( is_array( $query ) ) {
                          $query = wfArrayToCgi( $query );
                      }
                      if ( $query != '' ) {
                  Severity: Minor
                  Found in includes/GlobalFunctions.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

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

                  function wfShellExec( $cmd, &$retval = null, $environ = [],
                      $limits = [], $options = []
                  Severity: Minor
                  Found in includes/GlobalFunctions.php - About 35 mins to fix

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

                        string $old,
                        string $mine,
                        string $yours,
                        ?string &$simplisticMergeAttempt,
                        string &$mergeLeftovers = null
                    Severity: Minor
                    Found in includes/GlobalFunctions.php - About 35 mins to fix

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

                      function wfObjectToArray( $objOrArray, $recursive = true ) {
                          $array = [];
                          if ( is_object( $objOrArray ) ) {
                              $objOrArray = get_object_vars( $objOrArray );
                          }
                      Severity: Minor
                      Found in includes/GlobalFunctions.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 wfTransactionalTimeLimit has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function wfTransactionalTimeLimit() {
                          global $wgTransactionalTimeLimit;
                      
                          $timeout = RequestTimeout::singleton();
                          $timeLimit = $timeout->getWallTimeLimit();
                      Severity: Minor
                      Found in includes/GlobalFunctions.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 wfMerge has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function wfMerge(
                          string $old,
                          string $mine,
                          string $yours,
                          ?string &$simplisticMergeAttempt,
                      Severity: Minor
                      Found in includes/GlobalFunctions.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 true;
                      Severity: Major
                      Found in includes/GlobalFunctions.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

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

                          Avoid too many return statements within this method.
                          Open

                              return $services->getContentLanguage();
                          Severity: Major
                          Found in includes/GlobalFunctions.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                return array_udiff( $arr1, $arr2, $comparator );
                            Severity: Major
                            Found in includes/GlobalFunctions.php - About 30 mins to fix

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

                              function wfMsgReplaceArgs( $message, $args ) {
                                  # Fix windows line-endings
                                  # Some messages are split with explode("\n", $msg)
                                  $message = str_replace( "\r", '', $message );
                              
                              
                              Severity: Minor
                              Found in includes/GlobalFunctions.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 wfMergeErrorArrays has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                              function wfMergeErrorArrays( ...$args ) {
                                  $out = [];
                                  foreach ( $args as $errors ) {
                                      foreach ( $errors as $params ) {
                                          $originalParams = $params;
                              Severity: Minor
                              Found in includes/GlobalFunctions.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 wfDebugBacktrace has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                              function wfDebugBacktrace( $limit = 0 ) {
                                  static $disabled = null;
                              
                                  if ( $disabled === null ) {
                                      $disabled = !function_exists( 'debug_backtrace' );
                              Severity: Minor
                              Found in includes/GlobalFunctions.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

                                      $repl = [
                                          '"' => '&#34;', '&' => '&#38;', "'" => '&#39;', '<' => '&#60;',
                                          '=' => '&#61;', '>' => '&#62;', '[' => '&#91;', ']' => '&#93;',
                                          '{' => '&#123;', '|' => '&#124;', '}' => '&#125;',
                                          ';' => '&#59;', // a token inside language converter brackets
                              Severity: Major
                              Found in includes/GlobalFunctions.php and 1 other location - About 4 hrs to fix
                              includes/language/converters/ShiConverter.php on lines 76..111

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

                              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