wikimedia/mediawiki-core

View on GitHub
includes/media/SVGReader.php

Summary

Maintainability
D
2 days
Test Coverage

Function animateFilterAndLang has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

    private function animateFilterAndLang( $name ) {
        $this->debug( "animate filter for tag $name" );
        if ( $this->reader->nodeType !== XMLReader::ELEMENT ) {
            return;
        }
Severity: Minor
Found in includes/media/SVGReader.php - About 5 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 animateFilterAndLang has 59 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function animateFilterAndLang( $name ) {
        $this->debug( "animate filter for tag $name" );
        if ( $this->reader->nodeType !== XMLReader::ELEMENT ) {
            return;
        }
Severity: Major
Found in includes/media/SVGReader.php - About 2 hrs to fix

    File SVGReader.php has 256 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    /**
     * Extraction of SVG image metadata.
     *
    Severity: Minor
    Found in includes/media/SVGReader.php - About 2 hrs to fix

      Function read has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function read() {
              $keepReading = $this->reader->read();
      
              /* Skip until first element */
              while ( $keepReading && $this->reader->nodeType !== XMLReader::ELEMENT ) {
      Severity: Minor
      Found in includes/media/SVGReader.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 handleSVGAttribs has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          private function handleSVGAttribs() {
              $defaultWidth = self::DEFAULT_WIDTH;
              $defaultHeight = self::DEFAULT_HEIGHT;
              $aspect = 1.0;
              $width = null;
      Severity: Minor
      Found in includes/media/SVGReader.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 read has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function read() {
              $keepReading = $this->reader->read();
      
              /* Skip until first element */
              while ( $keepReading && $this->reader->nodeType !== XMLReader::ELEMENT ) {
      Severity: Minor
      Found in includes/media/SVGReader.php - About 1 hr to fix

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

            private function handleSVGAttribs() {
                $defaultWidth = self::DEFAULT_WIDTH;
                $defaultHeight = self::DEFAULT_HEIGHT;
                $aspect = 1.0;
                $width = null;
        Severity: Minor
        Found in includes/media/SVGReader.php - About 1 hr to fix

          Method __construct has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function __construct( $source ) {
                  $svgMetadataCutoff = MediaWikiServices::getInstance()->getMainConfig()
                      ->get( MainConfigNames::SVGMetadataCutoff );
                  $this->reader = new XMLReader();
          
          
          Severity: Minor
          Found in includes/media/SVGReader.php - About 1 hr to fix

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

                public static function scaleSVGUnit( $length, $viewportSize = 512 ) {
                    // Per CSS values spec, assume 96dpi.
                    static $unitLength = [
                        'px' => 1.0,
                        'pt' => 1.333333,
            Severity: Minor
            Found in includes/media/SVGReader.php - About 1 hr to fix

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

                  private function readField( $name, $metafield = null ) {
                      $this->debug( "Read field $metafield" );
                      if ( !$metafield || $this->reader->nodeType !== XMLReader::ELEMENT ) {
                          return;
                      }
              Severity: Minor
              Found in includes/media/SVGReader.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

              Avoid deeply nested control flow statements.
              Open

                                          if ( LanguageCode::isWellFormedLanguageTag( $itemPrefix ) ) {
                                              $this->languagePrefixes[$itemPrefix] = self::LANG_PREFIX_MATCH;
                                          }
              Severity: Major
              Found in includes/media/SVGReader.php - About 45 mins to fix

                Consider simplifying this complex logical expression.
                Open

                            if ( $isSVG && $tag === 'title' ) {
                                $this->readField( $tag, 'title' );
                            } elseif ( $isSVG && $tag === 'desc' ) {
                                $this->readField( $tag, 'description' );
                            } elseif ( $isSVG && $tag === 'metadata' && $type === XMLReader::ELEMENT ) {
                Severity: Major
                Found in includes/media/SVGReader.php - About 40 mins to fix

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

                      public function __construct( $source ) {
                          $svgMetadataCutoff = MediaWikiServices::getInstance()->getMainConfig()
                              ->get( MainConfigNames::SVGMetadataCutoff );
                          $this->reader = new XMLReader();
                  
                  
                  Severity: Minor
                  Found in includes/media/SVGReader.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

                  There are no issues that match your filters.

                  Category
                  Status