wikimedia/mediawiki-core

View on GitHub
includes/media/FormatMetadata.php

Summary

Maintainability
F
2 wks
Test Coverage

Function makeFormattedData has a Cognitive Complexity of 283 (exceeds 5 allowed). Consider refactoring.
Open

    public function makeFormattedData( $tags ) {
        $resolutionunit = !isset( $tags['ResolutionUnit'] ) || $tags['ResolutionUnit'] == 2 ? 2 : 3;
        unset( $tags['ResolutionUnit'] );

        // Ignore these complex values
Severity: Minor
Found in includes/media/FormatMetadata.php - About 5 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

Method makeFormattedData has 822 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function makeFormattedData( $tags ) {
        $resolutionunit = !isset( $tags['ResolutionUnit'] ) || $tags['ResolutionUnit'] == 2 ? 2 : 3;
        unset( $tags['ResolutionUnit'] );

        // Ignore these complex values
Severity: Major
Found in includes/media/FormatMetadata.php - About 4 days to fix

    File FormatMetadata.php has 1399 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /**
     * Formatting of image metadata values into human readable form.
     *
     * This program is free software; you can redistribute it and/or modify
    Severity: Major
    Found in includes/media/FormatMetadata.php - About 3 days to fix

      Function flattenArrayReal has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
      Open

          public function flattenArrayReal( $vals, $type = 'ul', $noHtml = false ) {
              if ( !is_array( $vals ) ) {
                  return $vals; // do nothing if not an array;
              }
      
      
      Severity: Minor
      Found in includes/media/FormatMetadata.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 collapseContactInfo has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          public function collapseContactInfo( array $vals ) {
              if ( !( isset( $vals['CiAdrExtadr'] )
                  || isset( $vals['CiAdrCity'] )
                  || isset( $vals['CiAdrCtry'] )
                  || isset( $vals['CiEmailWork'] )
      Severity: Minor
      Found in includes/media/FormatMetadata.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 collapseContactInfo has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function collapseContactInfo( array $vals ) {
              if ( !( isset( $vals['CiAdrExtadr'] )
                  || isset( $vals['CiAdrCity'] )
                  || isset( $vals['CiAdrCtry'] )
                  || isset( $vals['CiEmailWork'] )
      Severity: Major
      Found in includes/media/FormatMetadata.php - About 3 hrs to fix

        Method flattenArrayReal has 74 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function flattenArrayReal( $vals, $type = 'ul', $noHtml = false ) {
                if ( !is_array( $vals ) ) {
                    return $vals; // do nothing if not an array;
                }
        
        
        Severity: Major
        Found in includes/media/FormatMetadata.php - About 2 hrs to fix

          Function convertNewsCode has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
          Open

              private function convertNewsCode( $val ) {
                  if ( !preg_match( '/^\d{8}$/D', $val ) ) {
                      // Not a valid news code.
                      return $val;
                  }
          Severity: Minor
          Found in includes/media/FormatMetadata.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

          FormatMetadata has 24 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class FormatMetadata extends ContextSource {
              use ProtectedHookAccessorTrait;
          
              /**
               * Only output a single language for multi-language fields
          Severity: Minor
          Found in includes/media/FormatMetadata.php - About 2 hrs to fix

            Method convertNewsCode has 62 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function convertNewsCode( $val ) {
                    if ( !preg_match( '/^\d{8}$/D', $val ) ) {
                        // Not a valid news code.
                        return $val;
                    }
            Severity: Major
            Found in includes/media/FormatMetadata.php - About 2 hrs to fix

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

                  private function formatNum( $num, $round = false, $tagName = null ) {
                      $m = [];
                      if ( is_array( $num ) ) {
                          $out = [];
                          foreach ( $num as $number ) {
              Severity: Minor
              Found in includes/media/FormatMetadata.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 langItem has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function langItem( $value, $lang, $default = false, $noHtml = false ) {
                      if ( $lang === false && $default === false ) {
                          throw new InvalidArgumentException( '$lang and $default cannot both be false.' );
                      }
              
              
              Severity: Minor
              Found in includes/media/FormatMetadata.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 formatNum has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function formatNum( $num, $round = false, $tagName = null ) {
                      $m = [];
                      if ( is_array( $num ) ) {
                          $out = [];
                          foreach ( $num as $number ) {
              Severity: Minor
              Found in includes/media/FormatMetadata.php - About 1 hr to fix

                Method langItem has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function langItem( $value, $lang, $default = false, $noHtml = false ) {
                        if ( $lang === false && $default === false ) {
                            throw new InvalidArgumentException( '$lang and $default cannot both be false.' );
                        }
                
                
                Severity: Minor
                Found in includes/media/FormatMetadata.php - About 1 hr to fix

                  Consider simplifying this complex logical expression.
                  Open

                          if ( !( isset( $vals['CiAdrExtadr'] )
                              || isset( $vals['CiAdrCity'] )
                              || isset( $vals['CiAdrCtry'] )
                              || isset( $vals['CiEmailWork'] )
                              || isset( $vals['CiTelWork'] )
                  Severity: Critical
                  Found in includes/media/FormatMetadata.php - About 1 hr to fix

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

                        public function fetchExtendedMetadata( File $file ) {
                            $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                    
                            // If revision deleted, exit immediately
                            if ( $file->isDeleted( File::DELETED_FILE ) ) {
                    Severity: Minor
                    Found in includes/media/FormatMetadata.php - About 1 hr to fix

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

                          protected function sanitizeArrayForAPI( &$arr ) {
                              if ( !is_array( $arr ) ) {
                                  return;
                              }
                      
                      
                      Severity: Minor
                      Found in includes/media/FormatMetadata.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 formatCoords has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private function formatCoords( $coord, string $type ) {
                              if ( !is_numeric( $coord ) ) {
                                  wfDebugLog( 'exif', __METHOD__ . ": \"$coord\" is not a number" );
                                  return $this->literal( (string)$coord );
                              }
                      Severity: Minor
                      Found in includes/media/FormatMetadata.php - About 1 hr to fix

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

                            private function formatCoords( $coord, string $type ) {
                                if ( !is_numeric( $coord ) ) {
                                    wfDebugLog( 'exif', __METHOD__ . ": \"$coord\" is not a number" );
                                    return $this->literal( (string)$coord );
                                }
                        Severity: Minor
                        Found in includes/media/FormatMetadata.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 discardMultipleValues has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            protected function discardMultipleValues( &$metadata ) {
                                if ( !is_array( $metadata ) ) {
                                    return;
                                }
                                foreach ( $metadata as $key => &$field ) {
                        Severity: Minor
                        Found in includes/media/FormatMetadata.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

                        Consider simplifying this complex logical expression.
                        Open

                                        if ( !isset( $h[1] )
                                            || !isset( $m[1] )
                                            || !isset( $s[1] )
                                            || $h[1] == 0
                                            || $m[1] == 0
                        Severity: Major
                        Found in includes/media/FormatMetadata.php - About 40 mins to fix

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

                              protected function resolveMultilangValue( $value ) {
                                  if (
                                      !is_array( $value )
                                      || !isset( $value['_type'] )
                                      || $value['_type'] !== 'lang'
                          Severity: Minor
                          Found in includes/media/FormatMetadata.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 "<ol><li>" . implode( "</li>\n<li>", $vals ) . '</li></ol>';
                          Severity: Major
                          Found in includes/media/FormatMetadata.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return '<ul class="metadata-langlist">' . $content . '</ul>';
                            Severity: Major
                            Found in includes/media/FormatMetadata.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                                      return $defaultItem;
                              Severity: Major
                              Found in includes/media/FormatMetadata.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return "<ul><li>" . implode( "</li>\n<li>", $vals ) . '</li></ul>';
                                Severity: Major
                                Found in includes/media/FormatMetadata.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return null;
                                  Severity: Major
                                  Found in includes/media/FormatMetadata.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                        return $content;
                                    Severity: Major
                                    Found in includes/media/FormatMetadata.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                          return "\n*" . implode( "\n*", $vals );
                                      Severity: Major
                                      Found in includes/media/FormatMetadata.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                            return "\n#" . implode( "\n#", $vals );
                                        Severity: Major
                                        Found in includes/media/FormatMetadata.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                                  return Html::rawElement( 'span', [ 'lang' => $lang ], $item );
                                          Severity: Major
                                          Found in includes/media/FormatMetadata.php - About 30 mins to fix

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

                                                protected function resolveMultivalueValue( $value ) {
                                                    if ( !is_array( $value ) ) {
                                                        return $value;
                                                    }
                                                    if ( isset( $value['_type'] ) && $value['_type'] === 'lang' ) {
                                            Severity: Minor
                                            Found in includes/media/FormatMetadata.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 fetchExtendedMetadata has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                public function fetchExtendedMetadata( File $file ) {
                                                    $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                                            
                                                    // If revision deleted, exit immediately
                                                    if ( $file->isDeleted( File::DELETED_FILE ) ) {
                                            Severity: Minor
                                            Found in includes/media/FormatMetadata.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